FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlmap/lib/core/subprocessng.py at master · getcode2git/sqlmap · GitHub
getcode2git
/
sqlmap
Public
forked from
sqlmapproject/sqlmap
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlmap
/
lib
/
core
/
subprocessng.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
202 lines (168 loc) · 5.51 KB
Breadcrumbs
sqlmap
/
lib
/
core
/
subprocessng.py
Copy path
File metadata and controls
202 lines (168 loc) · 5.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env python
"""
Copyright (c) 2006-2015 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""
import
errno
import
os
import
subprocess
import
sys
import
time
from
lib
.
core
.
settings
import
IS_WIN
if
IS_WIN
:
try
:
from
win32file
import
ReadFile
,
WriteFile
from
win32pipe
import
PeekNamedPipe
except
ImportError
:
pass
import
msvcrt
else
:
import
select
import
fcntl
if
(
sys
.
hexversion
>>
16
)
>=
0x202
:
FCNTL
=
fcntl
else
:
import
FCNTL
def
blockingReadFromFD
(
fd
):
# Quick twist around original Twisted function
# Blocking read from a non-blocking file descriptor
output
=
""
while
True
:
try
:
output
+=
os
.
read
(
fd
,
8192
)
except
(
OSError
,
IOError
),
ioe
:
if
ioe
.
args
[
0
]
in
(
errno
.
EAGAIN
,
errno
.
EINTR
):
# Uncomment the following line if the process seems to
# take a huge amount of cpu time
# time.sleep(0.01)
continue
else
:
raise
break
if
not
output
:
raise
EOFError
(
"fd %s has been closed."
%
fd
)
return
output
def
blockingWriteToFD
(
fd
,
data
):
# Another quick twist
while
True
:
try
:
data_length
=
len
(
data
)
wrote_data
=
os
.
write
(
fd
,
data
)
except
(
OSError
,
IOError
),
io
:
if
io
.
errno
in
(
errno
.
EAGAIN
,
errno
.
EINTR
):
continue
else
:
raise
if
wrote_data
<
data_length
:
blockingWriteToFD
(
fd
,
data
[
wrote_data
:])
break
# the following code is taken from http://code.activestate.com/recipes/440554-module-to-allow-asynchronous-subprocess-use-on-win/
class
Popen
(
subprocess
.
Popen
):
def
recv
(
self
,
maxsize
=
None
):
return
self
.
_recv
(
'stdout'
,
maxsize
)
def
recv_err
(
self
,
maxsize
=
None
):
return
self
.
_recv
(
'stderr'
,
maxsize
)
def
send_recv
(
self
,
input
=
''
,
maxsize
=
None
):
return
self
.
send
(
input
),
self
.
recv
(
maxsize
),
self
.
recv_err
(
maxsize
)
def
get_conn_maxsize
(
self
,
which
,
maxsize
):
if
maxsize
is
None
:
maxsize
=
1024
elif
maxsize
<
1
:
maxsize
=
1
return
getattr
(
self
,
which
),
maxsize
def
_close
(
self
,
which
):
getattr
(
self
,
which
).
close
()
setattr
(
self
,
which
,
None
)
if
subprocess
.
mswindows
:
def
send
(
self
,
input
):
if
not
self
.
stdin
:
return
None
try
:
x
=
msvcrt
.
get_osfhandle
(
self
.
stdin
.
fileno
())
(
errCode
,
written
)
=
WriteFile
(
x
,
input
)
except
ValueError
:
return
self
.
_close
(
'stdin'
)
except
(
subprocess
.
pywintypes
.
error
,
Exception
),
why
:
if
why
[
0
]
in
(
109
,
errno
.
ESHUTDOWN
):
return
self
.
_close
(
'stdin'
)
raise
return
written
def
_recv
(
self
,
which
,
maxsize
):
conn
,
maxsize
=
self
.
get_conn_maxsize
(
which
,
maxsize
)
if
conn
is
None
:
return
None
try
:
x
=
msvcrt
.
get_osfhandle
(
conn
.
fileno
())
(
read
,
nAvail
,
nMessage
)
=
PeekNamedPipe
(
x
,
0
)
if
maxsize
<
nAvail
:
nAvail
=
maxsize
if
nAvail
>
0
:
(
errCode
,
read
)
=
ReadFile
(
x
,
nAvail
,
None
)
except
(
ValueError
,
NameError
):
return
self
.
_close
(
which
)
except
(
subprocess
.
pywintypes
.
error
,
Exception
),
why
:
if
why
[
0
]
in
(
109
,
errno
.
ESHUTDOWN
):
return
self
.
_close
(
which
)
raise
if
self
.
universal_newlines
:
read
=
self
.
_translate_newlines
(
read
)
return
read
else
:
def
send
(
self
,
input
):
if
not
self
.
stdin
:
return
None
if
not
select
.
select
([], [
self
.
stdin
], [],
0
)[
1
]:
return
0
try
:
written
=
os
.
write
(
self
.
stdin
.
fileno
(),
input
)
except
OSError
,
why
:
if
why
[
0
]
==
errno
.
EPIPE
:
# broken pipe
return
self
.
_close
(
'stdin'
)
raise
return
written
def
_recv
(
self
,
which
,
maxsize
):
conn
,
maxsize
=
self
.
get_conn_maxsize
(
which
,
maxsize
)
if
conn
is
None
:
return
None
flags
=
fcntl
.
fcntl
(
conn
,
fcntl
.
F_GETFL
)
if
not
conn
.
closed
:
fcntl
.
fcntl
(
conn
,
fcntl
.
F_SETFL
,
flags
|
os
.
O_NONBLOCK
)
try
:
if
not
select
.
select
([
conn
], [], [],
0
)[
0
]:
return
''
r
=
conn
.
read
(
maxsize
)
if
not
r
:
return
self
.
_close
(
which
)
if
self
.
universal_newlines
:
r
=
self
.
_translate_newlines
(
r
)
return
r
finally
:
if
not
conn
.
closed
:
fcntl
.
fcntl
(
conn
,
fcntl
.
F_SETFL
,
flags
)
def
recv_some
(
p
,
t
=
.1
,
e
=
1
,
tr
=
5
,
stderr
=
0
):
if
tr
<
1
:
tr
=
1
x
=
time
.
time
()
+
t
y
=
[]
r
=
''
if
stderr
:
pr
=
p
.
recv_err
else
:
pr
=
p
.
recv
while
time
.
time
()
<
x
or
r
:
r
=
pr
()
if
r
is
None
:
break
elif
r
:
y
.
append
(
r
)
else
:
time
.
sleep
(
max
((
x
-
time
.
time
())
/
tr
,
0
))
return
''
.
join
(
y
)
def
send_all
(
p
,
data
):
if
not
data
:
return
while
len
(
data
):
sent
=
p
.
send
(
data
)
if
not
isinstance
(
sent
,
int
):
break
data
=
buffer
(
data
,
sent
)
Back
|
FazBrowse Home
|
New Git URL