Skip to content

Commit d4cee81

Browse files
author
iphelix
committed
add files
0 parents  commit d4cee81

File tree

14 files changed

+3364
-0
lines changed

14 files changed

+3364
-0
lines changed

CHANGELOG

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Version 0.2.1
2+
* Fixed a Python 2.6 compatibility issue. (thanks Mehran Goudarzi)
3+
4+
Version 0.2
5+
6+
Changes
7+
* Added IPv6 support.
8+
* Added AAAA, MX, CNAME, NS, SOA and NAPTR support.
9+
* Added support for ANY queries (returns all known fake records).
10+
* Changed file format to support more DNS record types.
11+
* Added alternative DNS port support (contributed by fnv).
12+
* Added alternative listening port support for the server (contributed by Mark Straver).
13+
* Updated bundled dnslib library to the latest version - 0.8.2.
14+
* Included IPy library for IPv6 support.

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (C) 2013 Peter Kacherginsky
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README

Lines changed: 345 additions & 0 deletions
Large diffs are not rendered by default.

TODO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[*] Run in MiTM mode and inject fake DNS responses.

dnschef.ini

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[A] # Queries for IPv4 address records
2+
*.thesprawl.org=192.0.2.1
3+
4+
[AAAA] # Queries for IPv6 address records
5+
*.thesprawl.org=2001:db8::1
6+
7+
[MX] # Queries for mail server records
8+
*.thesprawl.org=mail.fake.com
9+
10+
[NS] # Queries for mail server records
11+
*.thesprawl.org=ns.fake.com
12+
13+
[CNAME] # Queries for alias records
14+
*.thesprawl.org=www.fake.com
15+
16+
[TXT] # Queries for text records
17+
*.thesprawl.org=fake message
18+
19+
[PTR]
20+
*.2.0.192.in-addr.arpa=fake.com
21+
22+
[SOA]
23+
*.thesprawl.org=ns.fake.com. hostmaster.fake.com. 1 10800 3600 604800 3600
24+
25+
[NAPTR]
26+
*.thesprawl.org=100 10 U E2U+sip !^.*$!sip:[email protected]! .

dnschef.py

Lines changed: 457 additions & 0 deletions
Large diffs are not rendered by default.

lib/IPy.py

Lines changed: 1378 additions & 0 deletions
Large diffs are not rendered by default.

lib/__init__.py

Whitespace-only changes.

lib/dnslib/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
from dns import *

lib/dnslib/bimap.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
class Bimap(object):
3+
4+
"""
5+
6+
A simple bi-directional map which returns either forward or
7+
reverse lookup of key through explicit 'lookup' method or
8+
through __getattr__ or __getitem__. If the key is not found
9+
in either the forward/reverse dictionaries it is returned.
10+
11+
>>> m = Bimap({1:'a',2:'b',3:'c'})
12+
>>> m[1]
13+
'a'
14+
>>> m.lookup('a')
15+
1
16+
>>> m.a
17+
1
18+
19+
"""
20+
21+
def __init__(self,forward):
22+
self.forward = forward
23+
self.reverse = dict([(v,k) for (k,v) in forward.items()])
24+
25+
def lookup(self,k,default=None):
26+
try:
27+
try:
28+
return self.forward[k]
29+
except KeyError:
30+
return self.reverse[k]
31+
except KeyError:
32+
if default:
33+
return default
34+
else:
35+
raise
36+
37+
def __getitem__(self,k):
38+
return self.lookup(k,k)
39+
40+
def __getattr__(self,k):
41+
return self.lookup(k,k)
42+
43+
if __name__ == '__main__':
44+
import doctest
45+
doctest.testmod()

lib/dnslib/bit.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
"""
3+
Some basic bit mainpulation utilities
4+
"""
5+
6+
FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
7+
8+
def hexdump(src, length=16, prefix=''):
9+
"""
10+
Print hexdump of string
11+
12+
>>> print hexdump("abcd\x00" * 4)
13+
0000 61 62 63 64 00 61 62 63 64 00 61 62 63 64 00 61 abcd.abc d.abcd.a
14+
0010 62 63 64 00 bcd.
15+
"""
16+
n = 0
17+
left = length / 2
18+
right = length - left
19+
result= []
20+
while src:
21+
s,src = src[:length],src[length:]
22+
l,r = s[:left],s[left:]
23+
hexa = "%-*s" % (left*3,' '.join(["%02x"%ord(x) for x in l]))
24+
hexb = "%-*s" % (right*3,' '.join(["%02x"%ord(x) for x in r]))
25+
lf = l.translate(FILTER)
26+
rf = r.translate(FILTER)
27+
result.append("%s%04x %s %s %s %s" % (prefix, n, hexa, hexb, lf, rf))
28+
n += length
29+
return "\n".join(result)
30+
31+
def get_bits(data,offset,bits=1):
32+
"""
33+
Get specified bits from integer
34+
35+
>>> bin(get_bits(0b0011100,2)
36+
0b1
37+
>>> bin(get_bits(0b0011100,0,4))
38+
0b1100
39+
40+
"""
41+
mask = ((1 << bits) - 1) << offset
42+
return (data & mask) >> offset
43+
44+
def set_bits(data,value,offset,bits=1):
45+
"""
46+
Set specified bits in integer
47+
48+
>>> bin(set_bits(0,0b1010,0,4))
49+
0b1010
50+
>>> bin(set_bits(0,0b1010,3,4))
51+
0b1010000
52+
"""
53+
mask = ((1 << bits) - 1) << offset
54+
clear = 0xffff ^ mask
55+
data = (data & clear) | ((value << offset) & mask)
56+
return data
57+
58+
def binary(n,count=16,reverse=False):
59+
"""
60+
Display n in binary (only difference from built-in `bin` is
61+
that this function returns a fixed width string and can
62+
optionally be reversed
63+
64+
>>> binary(6789)
65+
0001101010000101
66+
>>> binary(6789,8)
67+
10000101
68+
>>> binary(6789,reverse=True)
69+
1010000101011000
70+
71+
"""
72+
bits = [str((n >> y) & 1) for y in range(count-1, -1, -1)]
73+
if reverse:
74+
bits.reverse()
75+
return "".join(bits)
76+

lib/dnslib/buffer.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
import struct
3+
4+
class Buffer(object):
5+
6+
"""
7+
A simple data buffer - supports packing/unpacking in struct format
8+
9+
>>> b = Buffer()
10+
>>> b.pack("!BHI",1,2,3)
11+
>>> b.offset
12+
7
13+
>>> b.append("0123456789")
14+
>>> b.offset
15+
17
16+
>>> b.offset = 0
17+
>>> b.unpack("!BHI")
18+
(1, 2, 3)
19+
>>> b.get(5)
20+
'01234'
21+
>>> b.get(5)
22+
'56789'
23+
>>> b.update(7,"2s","xx")
24+
>>> b.offset = 7
25+
>>> b.get(5)
26+
'xx234'
27+
"""
28+
29+
def __init__(self,data=""):
30+
"""
31+
Initialise Buffer from data
32+
"""
33+
self.data = data
34+
self.offset = 0
35+
36+
def remaining(self):
37+
"""
38+
Return bytes remaining
39+
"""
40+
return len(self.data) - self.offset
41+
42+
def get(self,len):
43+
"""
44+
Gen len bytes at current offset (& increment offset)
45+
"""
46+
start = self.offset
47+
end = self.offset + len
48+
self.offset += len
49+
return self.data[start:end]
50+
51+
def pack(self,fmt,*args):
52+
"""
53+
Pack data at end of data according to fmt (from struct) & increment
54+
offset
55+
"""
56+
self.offset += struct.calcsize(fmt)
57+
self.data += struct.pack(fmt,*args)
58+
59+
def append(self,s):
60+
"""
61+
Append s to end of data & increment offset
62+
"""
63+
self.offset += len(s)
64+
self.data += s
65+
66+
def update(self,ptr,fmt,*args):
67+
"""
68+
Modify data at offset `ptr`
69+
"""
70+
s = struct.pack(fmt,*args)
71+
self.data = self.data[:ptr] + s + self.data[ptr+len(s):]
72+
73+
def unpack(self,fmt):
74+
"""
75+
Unpack data at current offset according to fmt (from struct)
76+
"""
77+
return struct.unpack(fmt,self.get(struct.calcsize(fmt)))
78+
79+
if __name__ == '__main__':
80+
import doctest
81+
doctest.testmod()

0 commit comments

Comments
 (0)