-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathfrmScTest.frm
691 lines (623 loc) · 22.6 KB
/
frmScTest.frm
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
VERSION 5.00
Begin VB.Form frmScTest
Caption = "scDbg - libemu Shellcode Logger Launch Interface"
ClientHeight = 7170
ClientLeft = 60
ClientTop = 345
ClientWidth = 10140
LinkTopic = "Form3"
ScaleHeight = 7170
ScaleWidth = 10140
StartUpPosition = 2 'CenterScreen
Begin VB.TextBox Text1
BeginProperty Font
Name = "Courier New"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 4950
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 2175
Width = 9960
End
Begin VB.Frame Frame1
Caption = "Options"
Height = 2145
Left = 60
TabIndex = 0
Top = 0
Width = 10005
Begin VB.CheckBox chkIgnoreRW
Caption = "Do not log RW"
Height = 195
Left = 5640
TabIndex = 29
Top = 480
Width = 1395
End
Begin VB.CommandButton cmdrowse
Caption = "..."
Height = 285
Index = 1
Left = 7860
TabIndex = 28
Top = 1080
Width = 465
End
Begin VB.TextBox txtTemp
Height = 315
Left = 1050
OLEDropMode = 1 'Manual
TabIndex = 27
Top = 1080
Width = 6705
End
Begin VB.CheckBox chktemp
Caption = "temp"
Height = 315
Left = 210
TabIndex = 26
Top = 1080
Width = 795
End
Begin VB.TextBox txtManualArgs
Height = 285
Left = 1800
TabIndex = 25
Top = 1440
Width = 5955
End
Begin VB.TextBox txtStartOffset
Height = 285
Left = 9240
TabIndex = 22
Text = "0"
Top = 180
Width = 675
End
Begin VB.CheckBox chkOffset
Caption = "Start Offset 0x"
Height = 255
Left = 7860
TabIndex = 23
Top = 180
Width = 1395
End
Begin VB.CommandButton cmdrowse
Caption = "..."
Height = 285
Index = 0
Left = 7860
TabIndex = 21
Top = 720
Width = 465
End
Begin VB.TextBox txtFopen
Height = 285
Left = 1035
OLEDropMode = 1 'Manual
TabIndex = 20
Top = 720
Width = 6720
End
Begin VB.CheckBox chkfopen
Caption = "fopen"
Height = 240
Left = 225
TabIndex = 19
Top = 780
Width = 1230
End
Begin VB.CheckBox ChkMemMon
Caption = "Monitor DLL Read/Write"
Height = 195
Left = 7860
TabIndex = 18
Top = 480
Width = 2055
End
Begin VB.CheckBox chkFindSc
Caption = "FindSc"
Height = 255
Left = 5640
TabIndex = 17
Top = 180
Width = 1095
End
Begin VB.CheckBox chkDebugShell
Caption = "Debug Shell"
Height = 195
Left = 4080
TabIndex = 16
Top = 480
Width = 1455
End
Begin VB.CheckBox chkUnlimitedSteps
Caption = "Unlimited steps"
Height = 255
Left = 4080
TabIndex = 15
Top = 180
Width = 1635
End
Begin VB.CheckBox chkApiTable
Caption = "Scan for Api table"
Height = 195
Left = 1920
TabIndex = 9
Top = 180
Width = 1995
End
Begin VB.CheckBox chkInteractiveHooks
Caption = "Use Interactive Hooks"
Height = 255
Left = 1920
TabIndex = 8
Top = 420
Width = 1935
End
Begin VB.CheckBox chkCreateDump
Caption = "Create Dump"
Height = 255
Left = 240
TabIndex = 7
Top = 420
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "Launch"
Height = 375
Left = 8370
TabIndex = 2
Top = 1395
Width = 1575
End
Begin VB.CheckBox chkReport
Caption = "Report Mode"
Height = 255
Left = 240
TabIndex = 1
Top = 180
Width = 1695
End
Begin VB.Label Label1
Caption = "Manual Arguments"
Height = 285
Left = 225
TabIndex = 24
Top = 1440
Width = 1410
End
Begin VB.Label Label6
Caption = "scdbg homepage"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Index = 8
Left = 3450
TabIndex = 14
Top = 1770
Width = 1335
End
Begin VB.Label Label6
Caption = "cmdline"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Index = 7
Left = 4830
TabIndex = 13
Top = 1770
Width = 675
End
Begin VB.Label Label6
Caption = "Save dump"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Index = 0
Left = 8160
TabIndex = 12
Top = 1770
Width = 855
End
Begin VB.Label Label6
Caption = "Video Demo"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Index = 2
Left = 5550
TabIndex = 11
Top = 1770
Width = 1035
End
Begin VB.Label Label6
Caption = "Help"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 195
Index = 6
Left = 6630
TabIndex = 10
Top = 1770
Width = 375
End
Begin VB.Label Label6
Caption = "Libemu HomePage"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Index = 4
Left = 1830
TabIndex = 6
Top = 1770
Width = 1455
End
Begin VB.Label Label6
Caption = "Manually Load File"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Index = 3
Left = 210
TabIndex = 5
Top = 1770
Width = 1335
End
Begin VB.Label Label6
Caption = "Example"
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 400
Underline = -1 'True
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Index = 5
Left = 7305
TabIndex = 4
Top = 1770
Width = 735
End
End
End
Attribute VB_Name = "frmScTest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim b() As Byte
Dim dlg As New clsCmnDlg
Dim scfile As String
Dim sctest As String
Dim lastcmdline As String
'Private Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long
'Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
'Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
'Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'Private Const SYNCHRONIZE = &H100000
'Private Const INFINITE = &HFFFF
Const INFINITE = &HFFFF
Const STARTF_USESHOWWINDOW = &H1
Private Enum enSW
SW_HIDE = 0
SW_NORMAL = 1
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
End Enum
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Enum enPriority_Class
NORMAL_PRIORITY_CLASS = &H20
IDLE_PRIORITY_CLASS = &H40
HIGH_PRIORITY_CLASS = &H80
End Enum
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Function SuperShell(ByVal App As String, ByVal WorkDir As String, Optional wait As Boolean = False, Optional dwMilliseconds As Long = 0, Optional start_size As enSW = SW_NORMAL, Optional Priority_Class As enPriority_Class = NORMAL_PRIORITY_CLASS) As Boolean
Dim pclass As Long
Dim sinfo As STARTUPINFO
Dim pinfo As PROCESS_INFORMATION
Dim sec1 As SECURITY_ATTRIBUTES
Dim sec2 As SECURITY_ATTRIBUTES
sec1.nLength = Len(sec1)
sec2.nLength = Len(sec2)
sinfo.cb = Len(sinfo)
sinfo.dwFlags = STARTF_USESHOWWINDOW
sinfo.wShowWindow = start_size
pclass = Priority_Class
If CreateProcess(vbNullString, App, sec1, sec2, False, pclass, 0&, WorkDir, sinfo, pinfo) Then
If wait Then WaitForSingleObject pinfo.hProcess, dwMilliseconds
SuperShell = True
Else
SuperShell = False
End If
End Function
'file msut exist for this to work which is stupid...
Public Function GetShortName(sFile As String) As String
Dim sShortFile As String * 67
Dim lResult As Long
'Make a call to the GetShortPathName API
lResult = GetShortPathName(sFile, sShortFile, _
Len(sShortFile))
'Trim out unused characters from the string.
GetShortName = left$(sShortFile, lResult)
End Function
Public Function InitInterface(Optional Shellcode As String = Empty)
scfile = Empty
If Not checkFor_sctest() Then Command1.enabled = False
If Len(Shellcode) = 0 Then
Text1 = "No text selected! you can use demo link."
Else
Text1 = HexDump(Shellcode)
b() = StrConv(Shellcode, vbFromUnicode, LANG_US)
End If
Me.Visible = True
End Function
Function checkFor_sctest() As Boolean
sctest = App.path & "\libemu\scdbg.exe"
If Not fso.FileExists(sctest) Then
MsgBox "Can not find scdbg? Should be distributed with installer?"
Else
checkFor_sctest = True
End If
End Function
Private Sub cmdrowse_Click(Index As Integer)
Dim f As String
f = dlg.OpenDialog(AllFiles)
If Index = 0 Then txtFopen.Text = f Else txtTemp = f
If Len(f) > 0 Then
If Index = 0 Then chkfopen.Value = 1 Else chktemp.Value = 1
If Index = 0 And Len(txtTemp) = 0 Then
txtTemp = fso.GetParentFolder(txtFopen) & "\"
chktemp.Value = 1
End If
End If
End Sub
Private Sub Command1_Click()
On Error Resume Next
scfile = App.path & "\libemu\sample.sc"
If fso.FileExists(scfile) Then Kill scfile
fso.writeFile scfile, StrConv(b(), vbUnicode, LANG_US)
sctest = App.path & "\libemu\scdbg.exe"
If Not fso.FileExists(sctest) Then
MsgBox "Can not find sctest in app.path exiting", vbCritical
Exit Sub
End If
Dim cmdline As String
Dim graphpth As String
scfile = Trim(Replace(scfile, Chr(0), Empty))
cmdline = GetShortName(sctest)
libemu = GetShortName(App.path & "\libemu")
If chkApiTable.Value = 1 Then cmdline = cmdline & " -api"
If chkInteractiveHooks.Value = 1 Then cmdline = cmdline & " -i"
If chkCreateDump.Value = 1 Then cmdline = cmdline & " -d"
If chkReport.Value = 1 Then cmdline = cmdline & " -r"
If chkUnlimitedSteps.Value = 1 Then cmdline = cmdline & " -s -1"
If chkDebugShell.Value = 1 Then cmdline = cmdline & " -vvv"
If chkFindSc.Value = 1 Then cmdline = cmdline & " -findsc"
If ChkMemMon.Value = 1 Then cmdline = cmdline & " -mdll"
If chktemp.Value = 1 Then cmdline = cmdline & " -temp " & GetShortName(txtTemp)
If chkIgnoreRW.Value = 1 Then cmdline = cmdline & " -norw"
If chkOffset.Value = 1 Then
If Not isHexNum(txtStartOffset) Then
MsgBox "Start offset is not a valid hex number: " & txtStartOffset, vbInformation
Exit Sub
End If
cmdline = cmdline & " -foff " & txtStartOffset
End If
If chkfopen.Value = 1 Then
If Not fso.FileExists(txtFopen.Text) Then
MsgBox "You must specify a valid file to open", vbInformation
Exit Sub
End If
cmdline = cmdline & " -fopen " & GetShortName(txtFopen)
End If
cmdline = cmdline & " -f sample.sc" & " " & txtManualArgs
cmdline = "cmd /k chdir /d " & libemu & "\ && " & cmdline
lastcmdline = cmdline
pid = Shell(cmdline, vbNormalFocus)
'If chkGraph.Value = 1 And fso.FileExists("c:\sc_graph.dot") Then
' graphpth = dlg.SaveDialog(AllFiles, RecommendedPath(), "Save Graph as", , Me.hwnd, RecommendedName(".gv"))
' If Len(graphpth) <> 0 Then
' If fso.FileExists(graphpth) Then Kill graphpth
' x = fso.ReadFile("c:\sc_graph.dot")
' fso.WriteFile graphpth, x
' End If
' fso.DeleteFile "c:\sc_graph.dot"
'End If
End Sub
Private Function RecommendedPath() As String
On Error Resume Next
RecommendedPath = fso.GetParentFolder(Form1.txtPDFPath)
End Function
Private Function RecommendedName(Optional ext = ".sc") As String
On Error Resume Next
Dim r As String
If Form1.txtPDFPath <> "Drag and drop pdf file here" Then
r = fso.GetBaseName(Form1.txtPDFPath)
End If
'old extension was .gv
If Len(r) = 0 Then
If ext = ".sc" Then r = "bytes.sc" Else r = "graph" & ext
Else
r = r & ext
End If
RecommendedName = r
End Function
Private Sub Form_Load()
Me.Icon = Form1.Icon
If fso.FileExists(Form1.txtPDFPath) Then
txtFopen = Form1.txtPDFPath
txtTemp = fso.GetParentFolder(txtFopen)
chktemp.Value = 1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Kill App.path & "\libemu\sample.unpack"
Kill App.path & "\libemu\graph.dot"
End Sub
Private Sub Label6_Click(Index As Integer)
On Error Resume Next
cap = Label6(Index).Caption
If InStr(cap, "Help") > 0 Then
Shell "cmd /k mode con lines=45 cols=100 && """ & App.path & "\libemu\scdbg.exe"" -h", vbNormalFocus
End If
If InStr(cap, "Home") > 0 Then
Shell "cmd /c start http://libemu.carnivore.it/"
End If
If InStr(cap, "Manual") > 0 Then
f = dlg.OpenDialog(AllFiles, , "Manually load shellcode file", Me.hwnd)
If Len(f) = 0 Then Exit Sub
InitInterface fso.ReadFile(f)
End If
If InStr(cap, "Example") > 0 Then
x = QuickDecode("ACACD13AD13FD4C3C5C5C5610BF38BDCBC49382A79DAC31BEA4E2B6A1A5226A36A26A35A3685A36A22C321A36A1EA56A56A36A16A3FA2B6A16A3E42B6252A3690AA3F42B71361BD71BE07F7FA3E42B263AA951244D5B5B695D2CA31BA9512B5E7E425C5D2CA313ABEA2EABEB2EADE05EF3ADD75EFF2BDC2BD47FC20D2A2A2A5E505E5A084D524D0A05410A1A081A081A081A0A4F4D5E0A5F4148495A411B1C084D524D2A442AC20B2A2A2A5D29EBC2252A2A2A5F4148495A411B1C084D524D2A442AC22F2A2A2A27AEC9D7D7D7EB7273757AABC67E1BEAA3D6A5626AA3FFDB849A6E837F7C79794402442979797D7BD700ABEE7EADEAEB683C793C203C683C0B3C0A3C093C103C0F3C0E3C")
x = HexStringUnescape(x)
Me.InitInterface CStr(x)
End If
If InStr(cap, "Demo") > 0 Then
Shell "cmd /c start http://www.youtube.com/watch?v=jFkegwFasIw"
End If
If InStr(cap, "scdbg") > 0 Then
Shell "cmd /c start http://sandsprite.com/blogs/index.php?uid=7^&pid=152"
End If
dump = App.path & "\libemu\sample.unpack"
If InStr(1, cap, "dump", 1) > 0 Then
If Not fso.FileExists(dump) Then
MsgBox "No dump file found. Maybe no changes were detected.", vbInformation
Else
pth = dlg.SaveDialog(AllFiles, , "Save dump as", , Me.hwnd, RecommendedName())
If Len(pth) = 0 Then Exit Sub
FileCopy dump, pth
End If
End If
graph = App.path & "\libemu\graph.dot"
If InStr(1, cap, "graph", 1) > 0 Then
If Not fso.FileExists(graph) Then
MsgBox "No graph file found", vbInformation
Else
pth = dlg.SaveDialog(AllFiles, , "Save graph as", , Me.hwnd, RecommendedName(".dot"))
If Len(pth) = 0 Then Exit Sub
FileCopy graph, pth
End If
End If
If InStr(1, cap, "cmdline", 1) > 0 Then
Clipboard.Clear
Clipboard.SetText lastcmdline
MsgBox Len(lastcmdline) & " bytes copied to clipboard", vbInformation
End If
End Sub
Private Sub txtFopen_OLEDragDrop(data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single)
On Error Resume Next
txtFopen.Text = data.Files(1)
chkfopen.Value = 1
If Len(txtTemp) = 0 Then
txtTemp = fso.GetParentFolder(txtFopen) & "\"
chktemp.Value = 1
End If
End Sub
Private Sub txtTemp_OLEDragDrop(data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single)
On Error Resume Next
txtTemp.Text = data.Files(1)
chktemp.Value = 1
End Sub