Skip to content

Commit 5620445

Browse files
committed
Implementation for an Issue sqlmapproject#292
1 parent 9e38ccb commit 5620445

10 files changed

Lines changed: 113 additions & 50 deletions

File tree

extra/beep/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
5+
See the file 'doc/COPYING' for copying permission
6+
"""
7+
8+
pass

extra/beep/beep.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
beep.py - Make a beep sound
5+
6+
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
7+
See the file 'doc/COPYING' for copying permission
8+
"""
9+
10+
import os
11+
import subprocess
12+
import sys
13+
import wave
14+
15+
BEEP_WAV_FILENAME = os.path.join(os.path.dirname(__file__), "beep.wav")
16+
17+
def beep():
18+
try:
19+
if subprocess.mswindows:
20+
_win_wav_play(BEEP_WAV_FILENAME)
21+
elif sys.platform == "darwin":
22+
_mac_beep()
23+
elif sys.platform == "linux2":
24+
_linux_wav_play(BEEP_WAV_FILENAME)
25+
else:
26+
_speaker_beep()
27+
except Exception:
28+
_speaker_beep()
29+
30+
def _speaker_beep():
31+
sys.stdout.write('\a') # doesn't work on modern Linux systems
32+
33+
try:
34+
sys.stdout.flush()
35+
except IOError:
36+
pass
37+
38+
def _mac_beep():
39+
import Carbon.Snd
40+
Carbon.Snd.SysBeep(1)
41+
42+
def _win_wav_play(filename):
43+
import winsound
44+
45+
winsound.PlaySound(filename, winsound.SND_FILENAME)
46+
47+
def _linux_wav_play(filename):
48+
import ctypes
49+
50+
PA_STREAM_PLAYBACK = 1
51+
PA_SAMPLE_S16LE = 3
52+
BUFFSIZE = 1024
53+
54+
class struct_pa_sample_spec(ctypes.Structure):
55+
_fields_ = [("format", ctypes.c_int), ("rate", ctypes.c_uint32), ("channels", ctypes.c_uint8)]
56+
57+
pa = ctypes.cdll.LoadLibrary("libpulse-simple.so.0")
58+
59+
wave_file = wave.open(filename, "rb")
60+
61+
pa_sample_spec = struct_pa_sample_spec()
62+
pa_sample_spec.rate = wave_file.getframerate()
63+
pa_sample_spec.channels = wave_file.getnchannels()
64+
pa_sample_spec.format = PA_SAMPLE_S16LE
65+
66+
error = ctypes.c_int(0)
67+
68+
pa_stream = pa.pa_simple_new(None, filename, PA_STREAM_PLAYBACK, None, "playback", ctypes.byref(pa_sample_spec), None, None, ctypes.byref(error))
69+
if not pa_stream:
70+
raise Exception("Could not create pulse audio stream: %s" % pa.strerror(ctypes.byref(error)))
71+
72+
while True:
73+
latency = pa.pa_simple_get_latency(pa_stream, error)
74+
if latency == -1:
75+
raise Exception("Getting latency failed")
76+
77+
buf = wave_file.readframes(BUFFSIZE)
78+
if not buf:
79+
break
80+
81+
if pa.pa_simple_write(pa_stream, buf, len(buf), error):
82+
raise Exception("Could not play file")
83+
84+
wave_file.close()
85+
86+
if pa.pa_simple_drain(pa_stream, error):
87+
raise Exception("Could not simple drain")
88+
89+
pa.pa_simple_free(pa_stream)
90+
91+
if __name__ == "__main__":
92+
beep()

extra/beep/beep.wav

45.7 KB
Binary file not shown.

lib/controller/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import socket
1313
import time
1414

15+
from extra.beep.beep import beep
1516
from lib.core.agent import agent
1617
from lib.core.common import arrayizeValue
1718
from lib.core.common import Backend
18-
from lib.core.common import beep
1919
from lib.core.common import extractRegexResult
2020
from lib.core.common import extractTextTagContent
2121
from lib.core.common import findDynamicContent

lib/core/common.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,50 +2046,6 @@ def urlencode(value, safe="%&=", convall=False, limit=False):
20462046

20472047
return result
20482048

2049-
def beep():
2050-
"""
2051-
Does an audible beep sound
2052-
Reference: http://de3.aminet.net/dev/src/clr.py.txt
2053-
"""
2054-
2055-
def _failsafe():
2056-
dataToStdout('\a', True)
2057-
2058-
if sys.platform == 'linux2':
2059-
for dev in ('/dev/audio', '/dev/oss', '/dev/dsp', '/dev/sound'):
2060-
if os.path.exists(dev):
2061-
try:
2062-
audio = file(dev, 'wb')
2063-
2064-
for _ in xrange(250):
2065-
audio.write(chr(32) * 4)
2066-
audio.write(chr(0) * 4)
2067-
2068-
audio.close()
2069-
return
2070-
except:
2071-
pass
2072-
2073-
try:
2074-
import curses
2075-
curses.initscr()
2076-
curses.beep()
2077-
curses.flash()
2078-
curses.endwin()
2079-
return
2080-
except:
2081-
_failsafe()
2082-
2083-
elif sys.platform == 'darwin':
2084-
try:
2085-
import Carbon.Snd
2086-
Carbon.Snd.SysBeep(1)
2087-
except:
2088-
_failsafe()
2089-
2090-
else:
2091-
_failsafe()
2092-
20932049
def runningAsAdmin():
20942050
"""
20952051
Returns True if the current process is run under admin privileges

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
"Miscellaneous": {
193193
"mnemonics": "string",
194194
"answers": "string",
195+
"beep": "boolean",
195196
"checkPayload": "boolean",
196197
"cleanup": "boolean",
197198
"dependencies": "boolean",

lib/core/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import tempfile
1414
import time
1515

16+
from extra.beep.beep import beep
1617
from lib.controller.controller import start
17-
from lib.core.common import beep
1818
from lib.core.common import clearConsoleLine
1919
from lib.core.common import dataToStdout
2020
from lib.core.common import readXmlFile

lib/parse/cmdline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ def cmdLineParser():
606606
miscellaneous.add_option("--answers", dest="answers",
607607
help="Set question answers (e.g. \"quit=N,follow=N\")")
608608

609+
miscellaneous.add_option("--beep", dest="beep", action="store_true",
610+
help="Make a beep sound when SQL injection is found")
611+
609612
miscellaneous.add_option("--check-payload", dest="checkPayload",
610613
action="store_true",
611614
help="Offline WAF/IPS/IDS payload detection testing")
@@ -658,9 +661,6 @@ def cmdLineParser():
658661
help="Simple wizard interface for beginner users")
659662

660663
# Hidden and/or experimental options
661-
parser.add_option("--beep", dest="beep", action="store_true",
662-
help=SUPPRESS_HELP)
663-
664664
parser.add_option("--profile", dest="profile", action="store_true",
665665
help=SUPPRESS_HELP)
666666

lib/techniques/error/use.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _oneShotErrorUse(expression, field=None):
107107
None)
108108

109109
if output is not None:
110-
output = getUnicode(output, kb.pageEncoding)
110+
output = getUnicode(output)
111111
else:
112112
trimmed = extractRegexResult(trimcheck, page, re.DOTALL | re.IGNORECASE) \
113113
or extractRegexResult(trimcheck, listToStrValue(headers.headers \

sqlmap.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,16 @@ mnemonics =
656656
# Set question answers (e.g. "quit=N,follow=N")
657657
answers =
658658

659+
# Make a beep sound when SQL injection is found
660+
# Valid: True or False
661+
beep = False
662+
659663
# Offline WAF/IPS/IDS payload detection testing.
664+
# Valid: True or False
660665
checkPayload = False
661666

662667
# Check for existence of WAF/IPS/IDS protection.
668+
# Valid: True or False
663669
checkWaf = False
664670

665671
# Clean up the DBMS by sqlmap specific UDF and tables.

0 commit comments

Comments
 (0)