●8일차(20241231)
각각에 우분투에 들어가서
sudo apt update
sudo apt install net-tools
sudo apt update
domain : sudo apt-get -y install bind9-utils
www: sudo apt -y install lamp-server^
mail: 메일서버 ( 143, 110, 25 )
sudo apt -y install dovecot-core dovecot-pop3d dovecot-imapd
sudo apt install postfix
1. 정보수집
su
nmap
nmap -v -sn 10.0.2.0/24 > result.txt
> 핑스캔 정보수집하는것
2. 10.0.2.10X에 열려있는 포트를 찾아라
su
touch user.txt(파일을 만들고)
touch passwd.txt
mv hydra.txt share
hydra -L user.txt -P passwd.txt 10.0.2.101 ssh
> 안됨 텍스트 파일에 들은게 없어서
nano user.txt
-----------------
m
ma
mas
mast
maste
master
-----------------
nano passwd.txt
------------------
1
12
123
1234
12345
123456
------------------
[도메인]
ssh master@10.0.2.101
var/log에 들어가서
tail -f auth.log (로그를 실시간을 볼수있다)
hydra -L user.txt -P passwd.txt 10.0.2.101 --> 공격하지 말라고 써있음
nmap -v -p1-65535 10.0.2.102 --> 열려있는 포트확인가능(root에서 함)
로그인이 가능한 서비스 ftp,ssh,telnet,imap,mysql 등은 아이디와 암호를 알고 있으면 접속이 가능(항상가능X)
*제발 gns만 쓸때는 네트워크 일반드라이브로 바꾸라고
ip nano에 들여쓰기 잘해야지
1. ping 스캔을 차단하라
2. www를 외부접속이 가능하도록 하자(ip는 냅두고)
kali root에서 nmap -v -p1-65535 10.0.2.102 이걸 통해 10.0.2.102에 열려있는 포트를 확인했다
10.0.2.102의 네트워크를 nat로 바꾸고 포트포워딩(22,80,21,443,3306)
포트를 차단하자
/var/www/html (웹기본페이지의 위치)
주인: root --> 그래서 연결은 안할거임 (수정어려움)
st.kr > /home/st/public_html
주인: st
msh.kr > /home/msh/public_html
주인: msh
naver.com > /home/naver/public_html
주인: naver
하나의 서버에 여러개의 웹이 있는 것을 웹호스팅이라 한다.
home에 st, msh adduser
cd /home
sudo adduser msh
sudo adduser st
su
cd /etc/skel (여기에 폴더를 만들어주면 계정을 생성할때마다 이 폴더가 각각 복사된다)
mkdir public_html(mkdir 폴더 만들기)
cd public_html
mkdir includes
mkdir logs
mkdir auth
mkdir board
touch index.php(파일 만들기)
cd includes
touch header.php
touch tail.php
touch db.php
ls
cd /home
cd /var/www/html
nano index.php
cat index.php
<?php
echo phpinfo();
?>
인터넷에 192.168.0.201/index.php
-->index.html index.php중 index.html이 먼저 반응한다.
-->php가 취약하다.(프로그래밍을 하게되면)
192.168.0.201/~msh (일반 홈페이지 작동)
-> not found
일반 계정을 활성화시키자 (root거는 수정하기 어려움)
cd /ec/skel
a2enmod userdir
systemctl restart apache2
-> forbidden
home/msh
ls -al
root:root > msh:msh
chown msh:msh index.html
(public_html도 root라면 st로 바꾸자)
chown st:st public_html
su st
chmod 711 $HOME
chmod 755 ~/public_html
su naver
cd ~
chmod 711 $HOME
chmod 755 ~/public_html
*정리(구글)
root@master:/home/naver# adduser google
비밀번호 치고
su google치고
cd ~ (너의 방으로 들어가라)
chmod 711 $HOME
chmod 755 ~/public_html
[edit plus]
설명 192.168.0.201
ftp서버 192.168.0.201
username st
password
디렉토리: /home/st/public_html
고급옵션 > passive ftp 모드 해제
문제1. ftp에 연결하라
xshell로 apt update
apt -y install vsftpd
밖으로 나갈때는 dns = 168.126.63.1
gns 안에서 dns = 10.0.2.102
-> 밖으로 나가야하므로 168.126.63.1 그래야 설치됨
nano /etc/vsftpd.conf
write_enable = YES (주석제거)
chroot_local_users=YES
chroot_listl_enable=YES
allow_writeable_chroot=YES (직접 적어줘야함)
-> 이거 안해도 되긴함
chroot_list_file=/etc/vsftpd.chroot_list
ls_recurse_enable=YES
xferlog_file 주석제거 (ftp는 활성화가 안되있어서 해줘야함)
local_root=public_html (직접 적어줘야함)
/etc/vsftpd.chroot_list 에 사용자를 넣어줘야함
nano /etc/vsftpd.chroot_list
------------------------------
st
master
msh
naver
---------------------------------
sysemctl restart vsftpd
-> 수정될때 마다 하자
새로 xshell을 들어가서 su st
cd ~
touch index.php
touch index.html --> editplus에도 생김
cd ..
st@web:~$ chmod 775 public_html/
공유파일에 index.php 파일을 복사해서 index.html에 붙혀
->깨져서 보임(프로그래밍 언어라)
php 언어에 6번째 줄
-> stylesheet이 작동되어야 함(근데 폴더에 없음)
root@web:/home/st/public_html# su st
st@web:~/public_html$ su
root@web:/home/st/public_html# sudo apt -y install lrzsz
-> 파일을 가져오기 위해 설치
st@web:~/public_html$ --> 여기에 stylesheet를 드래그
php 언어에 17번째 줄
-> menu.php가 작동되어야 함(근데 폴더에 업음)
st@web:~/public_html$ --> 여기에 menu를 드래그
근데 글자가 깨지고 이쁘지 않음
root@web:/home/st/public_html# apt -y install php8.3-fpm
a2enmod proxy_fcgi setenvif
a2enconf php8.3-fpm
systemctl restart php8.3-fpm apache2
--> 계정별로 php가 작동할 수 있게 만들어줌
웹 자체는 위험하지는 않는데 안에 들어가는 코드 때문에 위험해진다
리눅스를 가장 많이 활용하는 분야 > 웹서버 운영
로그인을 하려면 데이터베이스 라는게 필요하다
> 데이터베이스로 들어가자
루트상태에서 mysql
->mysql로 들어가짐
st@web:~/public_html$
-> 여기에 webhack.sql 드래그
----------------------------------------------------
create database st;
create user st@localhost identified by '123456';
grant all on st.* to st@localhost;
flush privileges;
create database msh;
create user msh@localhost identified by '123456';
grant all on msh.* to msh@localhost;
flush privileges;
create database naver;
create user naver@localhost identified by '123456';
grant all on naver.* to naver@localhost;
flush privileges;
-------------------------------------------------------
> mysql에 넣기
st@web:~/public_html$ 여기에 dbconfig 드래그
edit plus에서 새로고침 --> dbconfig.php
host = localhost
dbname = st
user = st
passwd = 123456
mysql에서 빠져나와서
root@web:/home/st/public_html# mysql -u st -p st < webhack.sql
-->mysql)
show databases;
use st;
show tables;
select * from auth;
---> 만들어진 데이터베이스가 나옴(유저, 아이디, 비밀번호)
index.php에서 login_chk.php 실행되어야 하는데 없으므로
st@web:~/public_html$ 여기에 드래그
저장이 안되므로 ls -al 쳐서 root로 되어있는거 확인
chown st:st login_chk.php
--> 로그인 화면으로 넘어감