Perimeter firewall scanning for open outbound ports
Setting up the attacker machine
Python listener script
#!/usr/bin/python
import re
import socket
import struct
import signal
open_ports = {}
def handler(signum, frame):
res = input("Ctrl-c was pressed. Do you really want to exit? y/n ")
if res == 'y':
print('')
print(open_ports)
exit(1)
signal.signal(signal.SIGINT, handler)
SO_ORIGINAL_DST = 80
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('0.0.0.0', 9999))
s.listen(10)
print('[i] Started listener on port 9999 ...')
print('')
while True:
csock, caddr = s.accept()
orig_dst = csock.getsockopt(socket.SOL_IP, SO_ORIGINAL_DST, 16)
orig_port = struct.unpack('>H', orig_dst[2:4])
orig_addr = socket.inet_ntoa(orig_dst[4:8])
if caddr[0] not in open_ports:
open_ports[caddr[0]] = []
open_ports[caddr[0]].append(orig_port)
print('[i] Connection from: ', caddr)
print('[*] Connection attempt to: ', orig_port)Setting up the NAT forward rule
To view the iptables rules use the following command:
Deleting the rule:
Setting up the victim machine
Last updated