-
Notifications
You must be signed in to change notification settings - Fork 0
/
out_example_netlib_merged.txt
151 lines (131 loc) · 4.6 KB
/
out_example_netlib_merged.txt
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
E:\Projects\GitHub\ImpSCAN>py impscan.py example/netlib/netlibclient.py
### Debug ###
line: import sys
line: import netlib
line:
line: def OnReceive(aMessage):
line: sys.stdout.write("\r{}".format(aMessage)) # Already includes a \n
line: sys.stdout.write("Say: ")
line: sys.stdout.flush()
line:
line: netlib.Initialize(True, OnReceive)
line:
line: try:
line: while True:
line: sys.stdout.write("Say: ")
line: sys.stdout.flush()
line: str_send = sys.stdin.readline() # Mistake 1: Potential for unlimited bandwidth
line: netlib.Send(str_send)
line: except:
line: netlib.Exit()
line:
Path: example/netlib/
CurrentDir: E:/Projects/GitHub/ImpSCAN/
Looking for files (['sys', 'netlib']) in E:/Projects/GitHub/ImpSCAN/example/netlib/:
Found an import named netlib in the path E:/Projects/GitHub/ImpSCAN/example/netlib/!
import sys
import netlib
def OnReceive(aMessage):
sys.stdout.write("\r{}".format(aMessage)) # Already includes a \n
sys.stdout.write("Say: ")
sys.stdout.flush()
netlib.Initialize(True, OnReceive)
try:
while True:
sys.stdout.write("Say: ")
sys.stdout.flush()
str_send = sys.stdin.readline() # Mistake 1: Potential for unlimited bandwidth
netlib.Send(str_send)
except:
netlib.Exit()
'''
Python3 Network Library Example
'''
import socket
import sys
from threading import Thread, Lock
import time
import os
pid = os.getpid()
# Globals
ip = "127.0.0.1"
port = 1313
buffer_size = 4096
reconnectTimeout = 3 # seconds
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Warning 1: No IPv6 implementation
def Initialize(aIsClient, aRecvCallbackFunc):
if (aIsClient):
# Try to connect
while not Connect():
print("Retrying in {} seconds...".format(reconnectTimeout))
time.sleep(reconnectTimeout)
# Set up receive and send threads
try:
rcv = Thread(target=Receive, args=(aRecvCallbackFunc,))
rcv.start()
netlibMain = Thread(target=NetlibMain)
netlibMain.start()
# Stop application on exception
except:
Exit(s)
def NetlibMain():
while s != None:
# Keep application alive
time.sleep(1)
# Funcs
def Connect():
try:
s.connect((ip, port))
return True
except Exception as ex:
print("Failed to connect. {}\n".format(ex))
return False
def Exit(aSocket = None):
print("\nGoodbye.")
if aSocket != None:
aSocket.close()
global s
s.close()
sys.exit()
os.system("kill -9 {}".format(pid))
def Send(aMessage):
try:
str_send = aMessage.encode('utf-8')
#str_send = str_send[:64] # This must fix mistake #1
#str_send = "test" # This also fixes mistake #1
#someVar = "potato"
s.send(str_send)
except Exception as ex:
print("Socket is goofed: {}".format(ex))
Exit(s)
def Receive(aRecvCallbackFunc):
while True:
if (s != None):
str_recv = s.recv(buffer_size)
if (len(str_recv) > 0):
aRecvCallbackFunc(str_recv.decode('utf-8'))
else:
break
else:
break
Exit(s)
Found call: socket.socket ('func', "Attribute(value=Name(id='socket', ctx=Load()), attr='socket', ctx=Load())")
It's coming from function named OnReceive
Found call: s.connect ('func', "Attribute(value=Name(id='s', ctx=Load()), attr='connect', ctx=Load())")
It's coming from function named Connect
Found call: s.send ('func', "Attribute(value=Name(id='s', ctx=Load()), attr='send', ctx=Load())")
It's coming from function named Send
s.send is using a variable named str_send
Assignment order of str_send:
= sys.stdin.readline
= aMessage.encode
Found call: s.recv ('func', "Attribute(value=Name(id='s', ctx=Load()), attr='recv', ctx=Load())")
It's coming from function named Receive
s.recv is using a variable named buffer_size
### Report ###
Errors: 1
Warnings: 1
Errors:
Socket s could be sending infinite amount of bytes because of: aMessage.encode
Warnings:
Socket connectivity is not configured for IPv6 connections