Day 13(2025.07.07.MON) - 마스커레이딩, 웹 크롤링(Attack.py)
- header.php -
- 메뉴에 물리보안 추가
● 내부에서 외부로 나가기 ●
1. Kali -> ubuntu 메일 전송
2. PC1 - 악성코드 설치
3. PC -> Hacker 연결(데이터 가져갈 수 있음, 연결 안되면 공격 불가)
- PC1의 192.168.0.1은 라우터가 모름(라우팅x)
- PC1이 바깥쪽으로 나가는 순간 변해야됨 192.168.0.1->125.246.95.152(마스커레이딩)
- PC1 -
ip 192.168.0.1 255.255.255.0 192.168.0.254
R2 -> UTM 패킷 분석
인터페이스
125.246.95.254(패킷 분석하면 게이트웨이로 빠지도록 설정해놨음)
- R2 설정해주기 -
[R2한방설정(OSPF)]
config t
hostname ST
interface FastEthernet0/0
ip address 125.246.95.254 255.255.255.0
no shutdown
exit
interface Serial1/0
ip address 1.1.1.2 255.255.255.252
no shutdown
exit
router ospf 1
network 125.246.95.0 0.0.0.255 area 0
network 1.1.1.0 0.0.0.3 area 0
router-id 2.2.2.2
exit
ip dhcp excluded-address 125.246.95.152 125.246.95.254
ip dhcp pool st
network 125.246.95.0 255.255.255.0
default-router 125.246.95.254
dns-server 125.246.95.152
lease 1 0 0 !
exit
라우팅해주면 ICMP 뜸
- R1 설정해주기 -
[R1한방설정(OSPF)]
config t
hostname Hacker
interface FastEthernet0/0
ip address 100.100.100.254 255.255.255.0
no shutdown
exit
interface Serial1/0
ip address 1.1.1.1 255.255.255.252
no shutdown
exit
router ospf 1
network 100.100.100.0 0.0.0.255 area 0
network 1.1.1.0 0.0.0.3 area 0
router-id 1.1.1.1
exit
ip dhcp excluded-address 100.100.100.1 100.100.100.254
ip dhcp pool hacker
network 100.100.100.0 255.255.255.0
default-router 100.100.100.254
dns-server 125.246.95.152
lease 1 0 0 !
exit
- 와이어샤크 멈추기
- 라우터 사이 와이어샤크 -
PC1 - ping 때리면 UTM 때문에 반응이 없음
- UTM -
방화벽 - Inside(Network) to Any 추가, 로그 트래픽 체크
Inside는 모든 서비스로 연결되어야 함
R1~R2 사이엔 192.168.0.1이 없으므로 나오면 안됨(라우터가 알 수 있는 주소로 방화벽에서 나올 때 바꿔줘야함)
● 마스커레이딩 ●
마스커레이딩에서 IP 바꿔줘야 요청, 반응함(192.168.0.1)
- Kali에서 Ubuntu2 연결 -
- Ubuntu2 -
root : nano /etc/netplan/50Tab
dhcp4: no, 192.168.1.1/24, 192.168.1.254, 192.168.1.2(주석 풀기)
sudo netplan apply
- Kali -
ssh -p 2222 master@geumsol.kr
(ssh 포트번호 22 변경할 시 UTM - NAT - ssh를 SSH 수정)
=> 접속 완료!
- Kali -
● dnsenum ●
- 다른 도메인 정보 수집 가능(Information Gethering)
- 도메인 앞에 붙은 호스트 이름은 비슷하기 때문에 사전으로 물어봤을 때 가능한 것만 찾아줌
- 위(공격) -
1. dnsenum geumsol.kr
3. nmap
nmap -v -A st.geumsol.kr
4. Webcrawling(Attack.py) - python Attack.py(실행)
- 아래(ubuntu:root) -
4-1. root@st:/home/master/public_html/logs# tail -f access.log(firefox - st.geumsol.kr 접속 해야 log 파일 올라옴)
- Win -
- 2. LMS 추가하기 -
- LMS = Learning Management System (학습 관리 시스템)
DNS 관리자에서 추가해주기
- Kali -
- 4. Webcrawling -
이메일 수집기 : 관리자 이메일을 모르기 때문에 이메일 수집
/home/kali:Attack.py
target - 내가 입력한 곳으로 바꿔줌, 입력 안하면 기본 디폴트로 감
- 로그 들어가서 뜨는지 확인 -
root@st: /home/master/public_html/logs# tail -f access.log(firefox - st.geumsol.kr 접속해야 log 파일 올라옴)
● 비정상적인 로그들 탐지해서 찍어보기 ●
ex) 100.100.100.1 - - [07/Jul/2025:05:58:58 +0000] "GET / HTTP/1.1" 200 333 "-" "python-requests/2.32.3"
[교재. 화이트 해커를 위한 암호와 해킹]
p.43 if __name__ == '__main__':
● Kali 공격 시작 필요한 프로그램(NAT, 기존 IPv4 삭제 후 설치) ●
- pip install requests(import requests)
- pip install bs4
- pip install beautifulsoup4
- pip install lxml
- pip install selenium
=> 설치 완료 후 네트워크, IP 원상복구(100.100.100.1 100.100.100.254 125.246.95.152)
- Ubuntu2 -
public_html : nano index.php
서버에 email : master@mail.geumsol.kr
- Kali -
- Attack.py -
import requests
from bs4 import BeautifulSoup
import re
class Attack:
target = "http://target.com"
def __init__(self,target):
#print(">>")
self.target=target
def crawling(self):
print(self.target)
response=requests.get(self.target)
print(response)
if response.status_code == 200: #정상이면
#print(response.text)
email_pattern=r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}" #정규표현
soup = BeautifulSoup(response.text,'html.parser') #문자열을 html로 변환
#print(soup,type(soup))
text_content = soup.get_text()
emails=re.findall(email_pattern,text_content) #문자열에서 이메일 패턴 찾기
unique_emails = set(emails)
print(unique_emails)
if __name__ == "__main__":
target="http://geumsol.kr"
attack = Attack(target)