티스토리 뷰

사용 전

  • pip 설치
  • scapy 모듈 설치


소스코드

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/python
from scapy.all import IP, TCP, UDP, sr1
from random import randint
from time import sleep
import sys
import getopt
import re
 
"""
dst_ip = '192.168.52.130'
src_port = [18888]
dst_port = [8888]
"""
 
def banner():
    print "==================================================="
    print "|               Simple_UDP_Fuzzer                 |"
    print "==================================================="
 
def usage():
    print >>sys.stderr, "[-] Simple_UDP_Fuzzer.py [-h|-p|-s|-S] -d dst_ip -D dst_port"
    print >>sys.stderr, "                         -h           : Help"
    print >>sys.stderr, "                         -p {tcp|udp} : TCP/UDP Protocol"
    print >>sys.stderr, "                         -s src_ip    : Source IP"
    print >>sys.stderr, "                         -S src_port  : Source Port"
    print >>sys.stderr, "                         -d dst_ip    : Destination IP"
    print >>sys.stderr, "                         -D dst_port  : Destination Port"
    sys.exit(-1)
 
def check_address(address):
    ip = None
    match = re.match("^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$", address)
    if match:
        ip = match.group(1)
    else:
        print >>sys.stderr, "invalid address " + address 
    
    return ip
 
def get_random_data(n=16):
    return ''.join([chr(randint(0,255)) for i in xrange(n)])
 
def create_packet(protocol=None, src_ip=None, dst_ip=None, src_port=None, dst_port=None):
    if src_ip:
        packet = IP(src=src_ip, dst=dst_ip)
    else:
        packet = IP(dst=dst_ip)
    
    if protocol is None: protocol = 'tcp'
    if protocol == 'tcp':
        if src_port:
            packet = packet/TCP(sport=src_port, dport=dst_port)
        else:
            packet = packet/TCP(dport=dst_port)
    elif protocol == 'udp':
        if src_port:
            packet = packet/UDP(sport=src_port, dport=dst_port)
        else:
            packet = packet/UDP(dport=dst_port)
    else:
        print "Unknown protocol"
        return None
 
    packet = packet/get_random_data(randint(1,65535))
 
    return packet
 
def fuzzing(netinfo):
    while True:
        packet = create_packet(**netinfo)
 
        with open("result.log""w") as fh:
            fh.write(str(packet))
 
        sr1(packet,timeout=1)
        sleep(0.5)
 
def config_netinfo():
    argv = sys.argv
    try:
        opts, args = getopt.getopt(argv[1:],
            "p:s:d:S:D:h",
            ["protocol=""src_ip=""dst_ip=""src_port=""dst_port=""help"])
    except getopt.error:
        usage()
 
    netinfo = {'protocol':'tcp'}
    for flag, value in opts:
        if flag in ['-p''--protocol']:
            if value not in ['tcp''udp']:
                usage()
            netinfo['protocol'= value
        elif flag in ['-s''--src_ip']:
            netinfo['src_ip'= check_address(value)
        elif flag in ['-d''--dst_ip']:
            netinfo['dst_ip'= check_address(value)
        elif flag in ['-S''--src_port']:
            netinfo['src_port'= int(value)
        elif flag in ['-D''--dst_port']:
            netinfo['dst_port'= int(value)
        elif flag in ['-h''--help']:
            usage()
        else:
            usage()
    
    if 'dst_ip' not in netinfo and 'dst_port' not in netinfo:
        usage()
 
    print "[+] Configured..."
    
    return netinfo
 
def main():
    banner()
    netinfo = config_netinfo()
    fuzzing(netinfo)
 
if __name__ == "__main__":
    main()
cs


Github : https://github.com/Tribal1012/MyLib/blob/master/MyWorkSpace/Python/Simple_Network_Fuzzer.py


scapy가 없는 코드(일부 코드가 작동되지 않아서 하드 코딩된 부분도 있음) : 


TCP의 세부 정보와 관련된 값을 세팅 안 한다.

그래서 이름이 UDP Fuzzer다.


기본이라서 덤프 퍼저로 작성해 두었는데, 좀 더 응용한다면 64번째 줄의 data 채우는 부분을 변경하면 된다.

'Programming > Python' 카테고리의 다른 글

python errno 사용  (0) 2018.01.20
Python hexdump 구현  (0) 2017.10.17
Windows python 모듈 설치 정리  (0) 2017.10.01
Windows Python 환경 변수 등록 및 pip 설치  (0) 2017.10.01
BeautifulSoup 안 쓰고 만드는 Python 크롤러  (2) 2017.03.31
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
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