-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Expand file tree
/
Copy pathgui.py
More file actions
1911 lines (1715 loc) · 78.1 KB
/
Copy pathgui.py
File metadata and controls
1911 lines (1715 loc) · 78.1 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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
"""
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
See the file 'LICENSE' for copying permission
"""
import io
import os
import subprocess
import sys
import tempfile
import threading
import time
import webbrowser
from lib.core.common import getSafeExString
from lib.core.common import saveConfig
from lib.core.data import paths
from lib.core.defaults import defaults
from lib.core.enums import MKSTEMP_PREFIX
from lib.core.exception import SqlmapMissingDependence
from lib.core.exception import SqlmapSystemException
from lib.core.settings import DEV_EMAIL_ADDRESS
from lib.core.settings import IS_WIN
from lib.core.settings import ISSUES_PAGE
from lib.core.settings import GIT_PAGE
from lib.core.settings import SITE
from lib.core.settings import VERSION_STRING
from lib.core.settings import WIKI_PAGE
from thirdparty.six.moves import queue as _queue
try:
_text_type = unicode
except NameError:
_text_type = str
_binary_type = str if sys.version_info[0] < 3 else bytes
_clock = getattr(time, "perf_counter", getattr(time, "clock", time.time))
def _toText(value):
"""Return a Unicode text value on both Python 2.7 and Python 3.x."""
if value is None:
return u""
if isinstance(value, _text_type):
return value
if isinstance(value, _binary_type):
try:
return value.decode("utf-8", "replace")
except Exception:
return _text_type(value)
try:
return _text_type(value)
except Exception:
return _text_type(repr(value))
def _toBytes(value):
"""Return UTF-8 bytes suitable for a binary subprocess pipe."""
if isinstance(value, _binary_type):
return value
return _toText(value).encode("utf-8", "replace")
def _waitForProcess(process, timeout):
"""Python 2 compatible replacement for Popen.wait(timeout=...)."""
deadline = _clock() + max(0.0, timeout)
while process.poll() is None and _clock() < deadline:
time.sleep(0.03)
return process.poll()
def _list2cmdline(arguments):
values = [_toText(_) for _ in arguments]
if sys.version_info[0] < 3:
return _toText(subprocess.list2cmdline([_toBytes(_) for _ in values]))
return _toText(subprocess.list2cmdline(values))
# A restrained security-tool palette: the layout stays familiar, while the darker
# navigation, cyan accents and terminal surfaces add a light Havij-era character.
PALETTE = {
"base": "#d7dce1",
"mantle": "#243545",
"crust": "#101820",
"surface0": "#f8fafb",
"surface1": "#8d98a3",
"surface2": "#e7ebef",
"light": "#ffffff",
"dark": "#3c4650",
"text": "#17212b",
"subtext": "#33414f",
"overlay": "#657381",
"title2": "#0b79a5",
"blue": "#164d73",
"sapphire": "#087caf",
"sky": "#169ec1",
"green": "#2d9659",
"teal": "#178b86",
"red": "#bd3f45",
"maroon": "#8c3d56",
"mauve": "#86549a",
"pink": "#b34e83",
"peach": "#c56d35",
"yellow": "#b78a18",
"lavender": "#6172b8",
"flamingo": "#bf5b72",
"gold": "#d29b22",
"navText": "#eef4f8",
"navMuted": "#a9bac8",
"navHover": "#31485d",
"panel": "#eef2f5",
"border": "#9ca7b1",
"success": "#2f9b5b",
"command": "#13232e",
"commandText": "#8de19b",
"consoleText": "#d8e7de",
"consoleMuted": "#8fa69a",
}
# a distinct accent color per section, so the sidebar icons read as a colorful, scannable set
ICON_COLORS = {
"Quick start": "yellow",
"Target": "red",
"Request": "sapphire",
"Optimization": "teal",
"Injection": "mauve",
"Detection": "sky",
"Techniques": "maroon",
"Fingerprint": "lavender",
"Enumeration": "green",
"Brute force": "peach",
"User-defined function injection": "pink",
"File system access": "gold",
"Operating system access": "blue",
"Windows registry access": "sapphire",
"General": "teal",
"Miscellaneous": "overlay",
}
# Options surfaced on the curated "Quick start" pane (by destination), in display order
QUICK_START_DESTS = (
"data", "cookie", "dbms", "level", "risk", "technique",
"getCurrentUser", "getCurrentDb", "getBanner", "isDba",
"getDbs", "getTables", "getColumns", "getPasswordHashes", "dumpTable",
"batch", "threads", "proxy", "tor",
)
# Short, readable sidebar labels for the (sometimes verbose) option-group titles
NAV_ALIASES = {
"User-defined function injection": "UDF injection",
"Operating system access": "OS access",
"Windows registry access": "Windows registry",
"File system access": "File system",
}
TARGET_PLACEHOLDER = "http://www.target.com/vuln.php?id=1"
HINT_DEFAULT = "Hover or focus a field to see what it does."
MAX_CONSOLE_LINES = 12000
MAX_SEARCH_RESULTS = 12
# --- parser-backend compatibility (works for both optparse and argparse objects) ---
def _parserGroups(parser):
groups = getattr(parser, "option_groups", None)
if groups is None:
groups = [_ for _ in getattr(parser, "_action_groups", []) if getattr(_, "title", None) not in (None, "positional arguments", "optional arguments", "options")]
return groups or []
def _groupOptions(group):
for attr in ("option_list", "_group_actions"):
if hasattr(group, attr):
return getattr(group, attr)
return []
def _groupTitle(group):
return getattr(group, "title", "") or ""
def _groupDescription(group):
if hasattr(group, "get_description"):
return group.get_description() or ""
return getattr(group, "description", "") or ""
def _optStrings(option):
if hasattr(option, "option_strings"): # argparse
return list(option.option_strings)
return list(getattr(option, "_short_opts", None) or []) + list(getattr(option, "_long_opts", None) or [])
def _optDest(option):
return getattr(option, "dest", None)
def _optHelp(option):
return getattr(option, "help", "") or ""
def _optChoices(option):
return getattr(option, "choices", None)
def _optTakesValue(option):
if hasattr(option, "takes_value"): # optparse Option
try:
return option.takes_value()
except Exception:
pass
return getattr(option, "nargs", 1) != 0 # argparse: store_true/false has nargs 0
def _optValueType(option):
kind = getattr(option, "type", None)
if kind in ("int", int):
return "int"
if kind in ("float", float):
return "float"
return "string"
def _optionLabel(option):
return ", ".join(_optStrings(option)) or (_optDest(option) or "")
def _preferredFlag(option):
strings = _optStrings(option)
longOptions = [_ for _ in strings if _.startswith("--")]
return (longOptions or strings or [""])[0]
def _quoteArg(value):
value = _toText(value)
if IS_WIN:
return _list2cmdline([value])
if not value:
return u"''"
safe = u"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@%+=:,./-"
if all(character in safe for character in value):
return value
return u"'" + value.replace(u"'", u"'\"'\"'") + u"'"
class _TooltipManager(object):
"""One shared tooltip/hint dispatcher for every option control.
Per-widget Python/Tcl bindings are surprisingly expensive when a pane contains
dozens of options. Widgets only receive a small Python attribute; four global
bindings handle the whole application.
"""
def __init__(self, owner, root, tk, palette, delay=500):
self._owner = owner
self._root = root
self._tk = tk
self._palette = palette
self._delay = delay
self._widget = None
self._tip = None
self._job = None
root.bind_all("<Enter>", self._enter, add="+")
root.bind_all("<Leave>", self._leave, add="+")
root.bind_all("<FocusIn>", self._focusIn, add="+")
root.bind_all("<FocusOut>", self._focusOut, add="+")
root.bind_all("<ButtonPress>", self._hide, add="+")
def attach(self, widget, text):
if text:
widget._sqlmap_help = text
def _textFor(self, widget):
return getattr(widget, "_sqlmap_help", "")
def _setHint(self, text):
try:
if hasattr(self._owner, "hint"):
self._owner.hint.set(text or HINT_DEFAULT)
except Exception:
pass
def _enter(self, event):
text = self._textFor(event.widget)
if not text:
return
self._widget = event.widget
self._setHint(text)
self._cancel()
try:
self._job = self._root.after(self._delay, self._show)
except Exception:
self._job = None
def _leave(self, event):
if event.widget is self._widget:
self._widget = None
self._cancel()
self._hide()
self._setHint(HINT_DEFAULT)
def _focusIn(self, event):
text = self._textFor(event.widget)
if text:
self._setHint(text)
def _focusOut(self, event):
if self._textFor(event.widget):
self._setHint(HINT_DEFAULT)
def _cancel(self):
if self._job is not None:
try:
self._root.after_cancel(self._job)
except Exception:
pass
self._job = None
def _show(self):
self._job = None
widget = self._widget
text = self._textFor(widget) if widget is not None else ""
if not text:
return
try:
if not widget.winfo_exists():
return
x = widget.winfo_rootx() + 18
y = widget.winfo_rooty() + widget.winfo_height() + 6
self._tip = tw = self._tk.Toplevel(widget)
# Toplevels are initially mapped by Tk at the default 0,0 position.
# Keep the tooltip withdrawn until its children have been measured and
# its final geometry has been assigned; otherwise X11 briefly paints an
# empty box in the screen corner before the real tooltip appears.
tw.withdraw()
tw.wm_overrideredirect(True)
try:
tw.wm_transient(self._root)
except Exception:
pass
self._tk.Label(tw, text=text, justify="left", background=self._palette["surface0"],
foreground=self._palette["text"], relief="solid", borderwidth=1,
wraplength=460, padx=10, pady=7).pack()
tw.update_idletasks()
width = max(1, tw.winfo_reqwidth())
height = max(1, tw.winfo_reqheight())
x = min(x, max(0, tw.winfo_screenwidth() - width - 8))
y = min(y, max(0, tw.winfo_screenheight() - height - 8))
tw.wm_geometry("%dx%d+%d+%d" % (width, height, x, y))
tw.deiconify()
tw.lift()
except Exception:
if self._tip is not None:
try:
self._tip.destroy()
except Exception:
pass
self._tip = None
def _hide(self, event=None):
self._cancel()
if self._tip is not None:
try:
self._tip.destroy()
except Exception:
pass
self._tip = None
class SqlmapGui(object):
def __init__(self, parser, tk, ttk, scrolledtext, messagebox, filedialog, font):
self.parser = parser
self.tk = tk
self.ttk = ttk
self.scrolledtext = scrolledtext
self.messagebox = messagebox
self.filedialog = filedialog
self.font = font
self.widgets = {} # dest -> (type, shared effective-value Tk variable)
self.vars = {} # dest -> shared Tk variable (one per option)
self.optionByDest = {}
self.optionOrder = []
self.sectionByDest = {}
self.searchIndex = []
for group in _parserGroups(parser):
title = _groupTitle(group)
for option in _groupOptions(group):
dest = _optDest(option)
if dest:
if dest not in self.optionByDest:
self.optionOrder.append(dest)
self.optionByDest[dest] = option
self.sectionByDest[dest] = title
for index, dest in enumerate(self.optionOrder):
option = self.optionByDest[dest]
section = self.sectionByDest.get(dest, "")
label = _optionLabel(option)
flag = _preferredFlag(option)
self.searchIndex.append((
dest,
index,
label,
section,
flag,
" ".join((label, dest, section, _optHelp(option))).lower(),
))
self.panes = {} # name -> outer frame
self.navItems = {} # name -> (row frame, accent strip, icon canvas, label, badge)
self.canvases = {} # name -> canvas (for wheel binding)
self.inners = {} # name -> scrollable inner frame (populated lazily)
self.builders = {} # name -> callable that populates the inner frame
self.built = set() # names whose content has been built
self.buildStates = {} # name -> generator for incremental pane construction
self._prebuildQueue = []
self._prebuildJob = None
self.badges = {} # name -> sidebar count badge label
self.sectionDests = {} # name -> [option dests in that section]
self.paneOrder = [] # nav order, for Up/Down navigation
self.currentPane = None
self.controlsByDest = {} # dest -> [(pane name, interactive widget)]
self.searchMatches = []
self.process = None
self.processQueue = None
self.processConfigFile = None
self.consoleWindow = None
self.consoleText = None
self.consoleStatus = None
self._runSerial = 0
self._refreshJob = None
self._searchJob = None
self._headerJob = None
self._suspendRefresh = False
try:
self.window = tk.Tk()
except Exception as ex:
raise SqlmapSystemException("unable to create GUI window ('%s')" % getSafeExString(ex))
self.tooltip = _TooltipManager(self, self.window, tk, PALETTE)
self._initializeVariables()
self._initFonts()
self._initStyle()
self._buildLayout()
self.window.protocol("WM_DELETE_WINDOW", self._closeApplication)
def _initializeVariables(self):
for dest in self.optionOrder:
option = self.optionByDest[dest]
isBool = not _optTakesValue(option)
otype = "bool" if isBool else _optValueType(option)
default = defaults.get(dest)
if isBool:
var = self.tk.BooleanVar(value=bool(default))
else:
var = self.tk.StringVar(value="" if default in (None, False) else default)
self.vars[dest] = var
self.widgets[dest] = (otype, var)
try:
var.trace("w", self._onOptionChanged)
except Exception:
pass
def _onOptionChanged(self, *unused):
if not self._suspendRefresh:
self._scheduleRefresh()
def _scheduleRefresh(self, delay=70):
if self._refreshJob is not None:
try:
self.window.after_cancel(self._refreshJob)
except Exception:
pass
self._refreshJob = self.window.after(delay, self._refreshDerivedState)
def _refreshDerivedState(self):
self._refreshJob = None
self._updateStats()
self.command.set(self._buildCommandString())
self._updateStatusLight()
def _updateStatusLight(self):
try:
canvas = self.statusLight
except AttributeError:
return
try:
canvas.delete("all")
if self._isRunning():
color = PALETTE["success"]
elif any(self._isOptionSet(_) for _ in self.widgets):
color = PALETTE["sky"]
else:
color = PALETTE["surface1"]
canvas.create_oval(2, 2, 10, 10, fill=color, outline=PALETTE["dark"])
except Exception:
pass
def _initFonts(self):
family = self.font.nametofont("TkDefaultFont").actual("family")
self.fonts = {
"body": (family, 10),
"bodyBold": (family, 10, "bold"),
"small": (family, 9),
"nav": (family, 10),
"title": (family, 18, "bold"),
"subtitle": (family, 9),
"mono": (self.font.nametofont("TkFixedFont").actual("family"), 10),
}
def _initStyle(self):
p = PALETTE
face = p["base"]
field = p["surface0"]
style = self.ttk.Style()
if "clam" in style.theme_names():
style.theme_use("clam")
style.configure(".", background=face, foreground=p["text"], fieldbackground=field,
bordercolor=p["border"], lightcolor=p["light"], darkcolor=p["surface1"],
troughcolor=p["surface2"], focuscolor=p["blue"], insertcolor=p["text"],
font=self.fonts["body"])
style.configure("TFrame", background=face)
style.configure("Bar.TFrame", background=p["panel"])
style.configure("Nav.TFrame", background=p["mantle"])
style.configure("Card.TFrame", background=p["panel"])
style.configure("Panel.TFrame", background=p["surface0"])
style.configure("PaneHeader.TFrame", background=p["surface0"])
style.configure("TLabel", background=face, foreground=p["text"])
style.configure("Title.TLabel", background=p["blue"], foreground="#ffffff", font=self.fonts["title"])
style.configure("Subtitle.TLabel", background=p["blue"], foreground="#dceaf2", font=self.fonts["subtitle"])
style.configure("Hint.TLabel", background=p["panel"], foreground=p["overlay"], font=self.fonts["small"])
style.configure("PanelHint.TLabel", background=p["surface0"], foreground=p["overlay"], font=self.fonts["small"])
style.configure("PanelLabel.TLabel", background=p["surface0"], foreground=p["blue"], font=self.fonts["bodyBold"])
style.configure("NavHint.TLabel", background=p["mantle"], foreground=p["navMuted"], font=self.fonts["small"])
style.configure("NavTitle.TLabel", background=p["mantle"], foreground=p["navText"], font=self.fonts["bodyBold"])
style.configure("Field.TLabel", background=p["panel"], foreground=p["text"])
style.configure("Desc.TLabel", background=p["panel"], foreground=p["overlay"], font=self.fonts["small"])
style.configure("Pane.TLabel", background=p["surface0"], foreground=p["blue"], font=self.fonts["title"])
style.configure("PaneCount.TLabel", background=p["surface0"], foreground=p["overlay"], font=self.fonts["small"])
style.configure("Stat.TLabel", background=p["panel"], foreground=p["overlay"], font=self.fonts["small"])
style.configure("Prompt.TLabel", background=field, foreground=p["text"], font=self.fonts["mono"])
style.configure("TButton", background=p["surface2"], foreground=p["text"], relief="raised", borderwidth=1,
lightcolor=p["light"], darkcolor=p["surface1"], bordercolor=p["border"],
focuscolor=p["blue"], padding=(11, 5))
style.map("TButton", background=[("active", p["surface0"]), ("pressed", p["surface1"])],
relief=[("pressed", "sunken")])
style.configure("Tool.TButton", padding=(9, 4), font=self.fonts["small"])
style.configure("Primary.TButton", background=p["success"], foreground="#ffffff", bordercolor=p["green"],
lightcolor="#78c89a", darkcolor="#17643a", padding=(12, 5), font=self.fonts["bodyBold"])
style.map("Primary.TButton", background=[("active", "#39aa68"), ("pressed", "#247c49")],
foreground=[("disabled", "#d7e4dc")])
style.configure("TEntry", fieldbackground=field, foreground=p["text"], relief="sunken", borderwidth=1,
bordercolor=p["border"], lightcolor=p["surface1"], darkcolor=p["light"],
insertcolor=p["text"], padding=5)
style.configure("Target.TEntry", fieldbackground="#ffffff", foreground=p["text"], relief="sunken", borderwidth=1,
bordercolor=p["sapphire"], lightcolor=p["surface1"], darkcolor=p["light"],
insertcolor=p["text"], padding=7, font=self.fonts["body"])
style.configure("Search.TEntry", fieldbackground="#192936", foreground=p["navText"], relief="flat", borderwidth=1,
bordercolor="#4c6376", lightcolor="#4c6376", darkcolor="#17242f",
insertcolor="#ffffff", padding=6)
style.configure("TCheckbutton", background=p["panel"], foreground=p["text"], focuscolor=p["panel"], padding=2,
indicatorbackground=field, indicatorforeground=p["blue"], indicatorrelief="sunken",
indicatorborderwidth=1, bordercolor=p["border"], lightcolor=p["surface1"], darkcolor=p["light"])
style.map("TCheckbutton", background=[("active", p["panel"])],
indicatorbackground=[("active", field), ("selected", field)])
style.configure("TCombobox", fieldbackground=field, background=p["surface2"], foreground=p["text"],
arrowcolor=p["blue"], relief="sunken", borderwidth=1, bordercolor=p["border"],
lightcolor=p["surface1"], darkcolor=p["light"], padding=4)
style.configure("Vertical.TScrollbar", background=p["surface2"], troughcolor=p["panel"],
bordercolor=p["border"], lightcolor=p["light"], darkcolor=p["surface1"],
arrowcolor=p["text"], relief="raised", width=16)
style.map("Vertical.TScrollbar", background=[("active", p["surface0"])])
self.window.configure(background=face)
def _buildLayout(self):
tk = self.tk
p = PALETTE
self.window.title("sqlmap GUI")
self.window.minsize(980, 690)
self._buildMenu()
self._buildHeader()
targetShell = tk.Frame(self.window, background=p["border"], borderwidth=0)
targetShell.pack(fill=tk.X, padx=16, pady=(10, 8))
target = self.ttk.Frame(targetShell, style="Panel.TFrame", padding=(14, 10, 14, 12))
target.pack(fill=tk.X, padx=1, pady=1)
tk.Frame(target, background=p["red"], height=3).pack(fill=tk.X, pady=(0, 9))
labelRow = self.ttk.Frame(target, style="Panel.TFrame")
labelRow.pack(fill=tk.X, pady=(0, 5))
self.ttk.Label(labelRow, text="TARGET URL", style="PanelLabel.TLabel").pack(side=tk.LEFT)
self.ttk.Label(labelRow, text="Ctrl+L", style="PanelHint.TLabel").pack(side=tk.RIGHT)
self.ttk.Label(labelRow, text=" e.g. %s" % TARGET_PLACEHOLDER, style="PanelHint.TLabel").pack(side=tk.LEFT)
targetRow = self.ttk.Frame(target, style="Panel.TFrame")
targetRow.pack(fill=tk.X)
urlVar = self._destVar("url", False)
self.targetEntry = self.ttk.Entry(targetRow, style="Target.TEntry", textvariable=urlVar)
self.targetEntry.pack(side=tk.LEFT, fill=tk.X, expand=True, ipady=1)
self.ttk.Button(targetRow, text="Paste", style="Tool.TButton", command=self._pasteTarget,
takefocus=False).pack(side=tk.LEFT, padx=(8, 0))
self.ttk.Button(targetRow, text="Clear", style="Tool.TButton", command=self._clearTarget,
takefocus=False).pack(side=tk.LEFT, padx=(6, 0))
self.controlsByDest.setdefault("url", []).append((None, self.targetEntry))
body = self.ttk.Frame(self.window, style="TFrame")
body.pack(expand=True, fill=tk.BOTH)
navHolder = self.ttk.Frame(body, style="Nav.TFrame", width=224)
navHolder.pack(side=tk.LEFT, fill=tk.Y)
navHolder.pack_propagate(False)
searchBar = self.ttk.Frame(navHolder, style="Nav.TFrame", padding=(11, 11, 11, 8))
searchBar.pack(fill=tk.X)
searchTitle = self.ttk.Frame(searchBar, style="Nav.TFrame")
searchTitle.pack(fill=tk.X, pady=(0, 5))
self.ttk.Label(searchTitle, text="OPTION FINDER", style="NavTitle.TLabel").pack(side=tk.LEFT)
self.ttk.Label(searchTitle, text="Ctrl+K", style="NavHint.TLabel").pack(side=tk.RIGHT)
self.searchVar = tk.StringVar(value="")
self.searchEntry = self.ttk.Entry(searchBar, style="Search.TEntry", textvariable=self.searchVar)
self.searchEntry.pack(fill=tk.X)
self.searchEntry.bind("<Return>", self._activateSearchResult)
self.searchEntry.bind("<Down>", self._searchMoveDown)
try:
self.searchVar.trace("w", self._scheduleSearch)
except Exception:
pass
self.searchList = tk.Listbox(navHolder, height=6, activestyle="dotbox", exportselection=False,
bg="#192936", fg=p["navText"], selectbackground=p["sapphire"],
selectforeground="#ffffff", relief="flat", borderwidth=1,
highlightthickness=1, highlightbackground="#4c6376",
font=self.fonts["small"])
self.searchList.bind("<ButtonRelease-1>", self._clickSearchResult)
self.searchList.bind("<Return>", self._activateSearchResult)
self.navCanvas = tk.Canvas(navHolder, background=p["mantle"], highlightthickness=0, borderwidth=0)
navScroll = self.ttk.Scrollbar(navHolder, orient="vertical", command=self.navCanvas.yview,
style="Vertical.TScrollbar")
self.nav = self.ttk.Frame(self.navCanvas, style="Nav.TFrame")
self.nav.bind("<Configure>", lambda e: self.navCanvas.configure(scrollregion=self.navCanvas.bbox("all")))
navWin = self.navCanvas.create_window((0, 0), window=self.nav, anchor="nw")
self.navCanvas.bind("<Configure>", lambda e: self.navCanvas.itemconfigure(navWin, width=e.width))
self.navCanvas.configure(yscrollcommand=navScroll.set)
self.navCanvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
navScroll.pack(side=tk.RIGHT, fill=tk.Y)
tk.Frame(body, background=p["border"], width=1).pack(side=tk.LEFT, fill=tk.Y)
self.content = self.ttk.Frame(body, style="Card.TFrame")
self.content.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
cmdBar = self.ttk.Frame(self.window, style="Bar.TFrame", padding=(16, 8))
cmdBar.pack(fill=tk.X)
self.ttk.Label(cmdBar, text=">_", style="PanelLabel.TLabel").pack(side=tk.LEFT, padx=(0, 8))
self.ttk.Button(cmdBar, text="Copy", style="Tool.TButton", command=self._copyCommand,
takefocus=False).pack(side=tk.RIGHT, padx=(7, 0))
self.ttk.Button(cmdBar, text="Reset", style="Tool.TButton", command=self.resetOptions,
takefocus=False).pack(side=tk.RIGHT, padx=(7, 0))
self.command = tk.StringVar(value="sqlmap.py")
cmdEntry = tk.Entry(cmdBar, textvariable=self.command, font=self.fonts["mono"],
bg=p["command"], fg=p["commandText"], readonlybackground=p["command"],
disabledforeground=p["commandText"], relief="flat", borderwidth=0,
highlightthickness=1, highlightbackground=p["border"],
highlightcolor=p["sapphire"], state="readonly")
cmdEntry.pack(side=tk.LEFT, fill=tk.X, expand=True, ipady=5)
hintBar = self.ttk.Frame(self.window, style="Bar.TFrame", padding=(16, 8))
hintBar.pack(fill=tk.X)
self.statusLight = tk.Canvas(hintBar, width=12, height=12, background=p["panel"],
highlightthickness=0, borderwidth=0)
self.statusLight.pack(side=tk.LEFT, padx=(0, 8))
self.stat = tk.StringVar(value="")
self.ttk.Label(hintBar, textvariable=self.stat, style="Stat.TLabel", anchor="e").pack(side=tk.RIGHT, padx=(12, 0))
self.hint = tk.StringVar(value=HINT_DEFAULT)
self.ttk.Label(hintBar, textvariable=self.hint, style="Hint.TLabel", anchor="w").pack(side=tk.LEFT, fill=tk.X, expand=True)
self._buildQuickStartPane()
for group in _parserGroups(self.parser):
self._buildGroupPane(group)
self._prebuildQueue = list(self.paneOrder)
self._selectPane("Quick start")
self.window.bind("<Down>", lambda e: self._navKey(1))
self.window.bind("<Up>", lambda e: self._navKey(-1))
for seq in ("<MouseWheel>", "<Button-4>", "<Button-5>"):
self.window.bind_all(seq, self._onWheel)
self.window.bind("<F5>", lambda e: self.run())
self.window.bind("<Control-r>", lambda e: self.run())
self.window.bind("<Control-Return>", lambda e: self.run())
self.window.bind("<Control-l>", lambda e: self._focusTarget())
self.window.bind("<Control-k>", lambda e: self._focusSearch())
self.window.bind("<Escape>", self._escapeAction)
self.window.bind("<Control-s>", lambda e: self.saveConfigDialog())
self.window.bind("<Control-o>", lambda e: self.loadConfig())
self._enableSelectAll()
self._refreshDerivedState()
self._center(self.window, 1060, 750)
self._schedulePanePrebuild(60)
def _enableSelectAll(self):
# Tk binds Ctrl-A to "cursor to line start" by default; rebind it to select-all,
# which is what users expect (covers entries, comboboxes and the console text widget)
def selectEntry(event):
try:
event.widget.select_range(0, "end")
event.widget.icursor("end")
except Exception:
pass
return "break"
def selectText(event):
try:
event.widget.tag_add("sel", "1.0", "end-1c")
except Exception:
pass
return "break"
for cls in ("TEntry", "Entry", "TCombobox"):
self.window.bind_class(cls, "<Control-a>", selectEntry)
self.window.bind_class(cls, "<Control-A>", selectEntry)
for seq in ("<Control-a>", "<Control-A>"):
self.window.bind_class("Text", seq, selectText)
def _buildMenu(self):
p = PALETTE
menuKw = dict(bg=p["panel"], fg=p["text"], activebackground=p["sapphire"],
activeforeground="#ffffff")
menubar = self.tk.Menu(self.window, borderwidth=0, **menuKw)
filemenu = self.tk.Menu(menubar, tearoff=0, **menuKw)
filemenu.add_command(label="Load configuration...", command=self.loadConfig)
filemenu.add_command(label="Save configuration...", command=self.saveConfigDialog)
filemenu.add_command(label="Reset all options", command=self.resetOptions)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=self._closeApplication)
menubar.add_cascade(label="File", menu=filemenu)
menubar.add_command(label="Run", command=self.run)
helpmenu = self.tk.Menu(menubar, tearoff=0, **menuKw)
helpmenu.add_command(label="Official site", command=lambda: webbrowser.open(SITE))
helpmenu.add_command(label="GitHub", command=lambda: webbrowser.open(GIT_PAGE))
helpmenu.add_command(label="Wiki", command=lambda: webbrowser.open(WIKI_PAGE))
helpmenu.add_command(label="Report issue", command=lambda: webbrowser.open(ISSUES_PAGE))
helpmenu.add_separator()
helpmenu.add_command(label="About", command=lambda: self.messagebox.showinfo(
"About", "%s\n\n (%s)" % (VERSION_STRING, DEV_EMAIL_ADDRESS)))
menubar.add_cascade(label="Help", menu=helpmenu)
self.window.config(menu=menubar)
def _buildHeader(self):
self._runHover = False
self.header = self.tk.Canvas(self.window, height=76, highlightthickness=0, borderwidth=0, background=PALETTE["base"])
self.header.pack(fill=self.tk.X)
self.header.bind("<Configure>", self._scheduleHeaderDraw)
def _scheduleHeaderDraw(self, event=None):
if self._headerJob is not None:
try:
self.window.after_cancel(self._headerJob)
except Exception:
pass
self._headerJob = self.window.after(35, self._drawHeader)
def _interp(self, color1, color2, ratio):
a = [int(color1[_:_ + 2], 16) for _ in (1, 3, 5)]
b = [int(color2[_:_ + 2], 16) for _ in (1, 3, 5)]
return "#%02x%02x%02x" % tuple(int(a[_] + (b[_] - a[_]) * ratio) for _ in range(3))
def _drawHeader(self):
"""Draw the header only for resize or process-state changes.
Keep this deliberately cheap. Redrawing a canvas from an <Enter>/<Leave>
callback can remove the item currently under the pointer, which generates a
matching leave/enter pair and can turn into an event/redraw loop on Tk/X11.
"""
self._headerJob = None
p = PALETTE
c = self.header
c.delete("all")
width = max(1, c.winfo_width())
height = 76
# A small, fixed number of primitives paints faster and more consistently
# than a strip-per-gradient header, especially on X11 and remote displays.
c.create_rectangle(0, 0, width, height, outline="", fill="#17445f")
c.create_rectangle(0, 0, 6, height, outline="", fill=p["sky"])
c.create_rectangle(6, height - 4, width, height, outline="", fill="#0e7697")
c.create_line(22, 64, max(22, width - 160), 64, fill="#39738a")
c.create_text(26, 26, text="sqlmap", anchor="w", fill="#ffffff", font=self.fonts["title"])
c.create_text(124, 30, text=VERSION_STRING.replace("sqlmap/", "v"), anchor="w",
fill="#bfe1ed", font=self.fonts["subtitle"])
c.create_text(26, 52, text="automatic SQL injection and database takeover tool", anchor="w",
fill="#dcecf2", font=self.fonts["small"])
self._drawRunButton(width, height)
def _isRunning(self):
return self.process is not None and self.process.poll() is None
def _drawRunButton(self, width, height):
p = PALETTE
c = self.header
running = self._isRunning()
bw, bh = 116, 34
x0 = width - bw - 22
y0 = (height - bh) // 2
x1, y1 = x0 + bw, y0 + bh
baseFill = p["red"] if running else p["success"]
fill = ("#d15056" if running else "#3bae6b") if self._runHover else baseFill
c.create_rectangle(x0, y0, x1, y1, fill=fill, outline="#d9f1e3", width=1,
tags=("runbtn", "runpill"))
c.create_line(x0 + 1, y0 + 1, x1 - 1, y0 + 1, fill="#8fd2aa" if not running else "#ef9da1",
tags="runbtn")
c.create_line(x0 + 1, y1 - 1, x1 - 1, y1 - 1, fill="#17613a" if not running else "#75252a",
tags="runbtn")
cy = (y0 + y1) // 2
tx = x0 + 23
if running:
c.create_rectangle(tx, cy - 6, tx + 11, cy + 6, fill="#ffffff", outline="",
tags=("runbtn", "runico"))
else:
c.create_polygon(tx, cy - 6, tx, cy + 6, tx + 10, cy, fill="#ffffff", outline="",
tags=("runbtn", "runico"))
c.create_text((x0 + x1) // 2 + 8, cy, text=("Stop" if running else "Run"), fill="#ffffff",
font=self.fonts["bodyBold"], tags=("runbtn", "runico"))
c.tag_bind("runbtn", "<Button-1>", lambda e: self._runButtonAction())
c.tag_bind("runbtn", "<Enter>", lambda e: self._hoverRun(True))
c.tag_bind("runbtn", "<Leave>", lambda e: self._hoverRun(False))
def _runButtonAction(self):
if self._isRunning():
self.stopProcess()
else:
self.run()
def _hoverRun(self, on):
"""Update only the existing button items; never rebuild the header here."""
self._runHover = on
try:
running = self._isRunning()
if on:
fill = "#d15056" if running else "#3bae6b"
else:
fill = PALETTE["red"] if running else PALETTE["success"]
self.header.itemconfigure("runpill", fill=fill)
self.header.configure(cursor="hand2" if on else "")
except Exception:
pass
def _drawIcon(self, c, name, col):
# minimal line-art icons, drawn as vectors so they render everywhere and need no assets
c.delete("all")
def line(*pts, **kw):
c.create_line(*pts, fill=col, width=2, capstyle="round", joinstyle="round", **kw)
def oval(x0, y0, x1, y1, filled=False):
c.create_oval(x0, y0, x1, y1, outline=col, width=2, fill=(col if filled else ""))
def rect(x0, y0, x1, y1, filled=False):
c.create_rectangle(x0, y0, x1, y1, outline=col, width=2, fill=(col if filled else ""))
def poly(*pts):
c.create_polygon(*pts, fill=col, outline="")
def arc(x0, y0, x1, y1, start, extent):
c.create_arc(x0, y0, x1, y1, start=start, extent=extent, outline=col, width=2, style="arc")
def dot(x, y, r=2):
c.create_oval(x - r, y - r, x + r, y + r, fill=col, outline="")
def glyph(text, size=11):
c.create_text(11, 11, text=text, fill=col, font=(self.fonts["bodyBold"][0], size, "bold"))
if name == "Quick start":
poly(12, 3, 6, 12, 10, 12, 9, 19, 16, 9, 11, 9)
elif name == "Target":
oval(4, 4, 18, 18)
dot(11, 11, 2)
elif name == "Request":
line(4, 8, 17, 8, arrow="last")
line(18, 14, 5, 14, arrow="last")
elif name == "Optimization":
arc(4, 6, 18, 20, 0, 180)
line(11, 13, 15, 8)
elif name == "Injection":
# syringe: thumb rest + plunger rod + flange + barrel + needle (no arrowhead, so it reads as a needle not a cross)
line(9, 2, 13, 2)
line(11, 2, 11, 5)
line(6, 5, 16, 5)
rect(8, 5, 14, 14)
line(11, 14, 11, 20)
elif name == "Detection":
oval(4, 4, 13, 13)
line(12, 12, 18, 18)
elif name == "Techniques":
oval(7, 7, 15, 15)
line(11, 2, 11, 6)
line(11, 16, 11, 20)
line(2, 11, 6, 11)
line(16, 11, 20, 11)
elif name == "Fingerprint":
# tightly nested tall loops with the gap at the bottom (fingertip ridges), plus a central core
arc(3, 1, 19, 21, 285, 330)
arc(5, 4, 17, 18, 285, 330)
arc(7, 7, 15, 15, 285, 330)
arc(9, 10, 13, 12, 285, 330)
elif name == "Enumeration":
oval(4, 3, 18, 7)
line(4, 5, 4, 16)
line(18, 5, 18, 16)
arc(4, 12, 18, 18, 180, 180)
elif name == "Brute force":
oval(3, 7, 11, 15)
line(9, 11, 19, 11)
line(16, 11, 16, 15)
line(19, 11, 19, 14)
elif name == "User-defined function injection":
glyph("fx", 11)
elif name == "File system access":
poly(3, 7, 8, 7, 10, 9, 19, 9, 19, 17, 3, 17)
elif name == "Operating system access":
rect(3, 5, 19, 17)
line(6, 9, 9, 11)
line(6, 13, 9, 13)
elif name == "Windows registry access":
# the waving Windows flag (4 slanted panes) rather than a plain 2x2 grid
poly(4, 6, 10, 5, 10, 11, 4, 12)
poly(12, 5, 18, 4, 18, 10, 12, 11)
poly(4, 13, 10, 12, 10, 18, 4, 19)
poly(12, 12, 18, 11, 18, 17, 12, 18)
elif name == "General":
line(4, 6, 18, 6)
dot(14, 6)
line(4, 11, 18, 11)
dot(8, 11)
line(4, 16, 18, 16)
dot(13, 16)
elif name == "Miscellaneous":
dot(5, 11)
dot(11, 11)
dot(17, 11)
else:
dot(11, 11, 3)
def _addPane(self, name, navText):
p = PALETTE
tk = self.tk
row = tk.Frame(self.nav, background=p["mantle"])
row.pack(fill=tk.X)
strip = tk.Frame(row, background=p["mantle"], width=3)
strip.pack(side=tk.LEFT, fill=tk.Y)
icon = tk.Canvas(row, width=22, height=22, highlightthickness=0, borderwidth=0, background=p["mantle"])
icon.pack(side=tk.LEFT, padx=(13, 0), pady=8)
self._drawIcon(icon, name, self._iconColor(name))
badge = tk.Label(row, text="", background=p["mantle"], foreground=p["navMuted"], font=self.fonts["small"])
badge.pack(side=tk.RIGHT, padx=(0, 12))
self.badges[name] = badge
lab = tk.Label(row, text=navText, background=p["mantle"], foreground=p["navText"],
font=self.fonts["nav"], anchor="w", padx=10, pady=9)
lab.pack(side=tk.LEFT, fill=tk.X, expand=True)
for w in (row, lab, strip, icon, badge):
w.bind("<Button-1>", lambda e, n=name: self._selectPane(n))
w.bind("<Enter>", lambda e, n=name: self._navHover(n, True))
w.bind("<Leave>", lambda e, n=name: self._navHover(n, False))
self.navItems[name] = (row, strip, icon, lab, badge)
self.paneOrder.append(name)
outer = self.ttk.Frame(self.content, style="Card.TFrame")
canvas = tk.Canvas(outer, background=p["panel"], highlightthickness=0, borderwidth=0)
scrollbar = self.ttk.Scrollbar(outer, orient="vertical", command=canvas.yview, style="Vertical.TScrollbar")
inner = self.ttk.Frame(canvas, style="Card.TFrame", padding=(24, 20))
inner.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))
window_id = canvas.create_window((0, 0), window=inner, anchor="nw")
canvas.bind("<Configure>", lambda e: canvas.itemconfigure(window_id, width=e.width))
canvas.configure(yscrollcommand=scrollbar.set)
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
self.panes[name] = outer
self.canvases[name] = canvas
self.inners[name] = inner
return inner
def _iconColor(self, name):
return PALETTE.get(ICON_COLORS.get(name, "subtext"), PALETTE["subtext"])
def _navHover(self, name, entering):
if entering:
self._prioritizePaneBuild(name)
if name == self.currentPane:
return
bg = PALETTE["navHover"] if entering else PALETTE["mantle"]
row, strip, icon, lab, badge = self.navItems[name]
for w in (row, strip, icon, lab, badge):
w.configure(background=bg)
def _navKey(self, delta):
try:
focused = self.window.focus_get()
except Exception:
focused = None
if isinstance(focused, (self.ttk.Entry, self.ttk.Combobox)):
return None
if self.paneOrder: