# Password on shares

## Configuring

### Prerequisite&#x20;

{% content-ref url="page-3" %}
[page-3](https://ad-lab.gitbook.io/building-a-windows-ad-lab/vulnerabilities-and-misconfigurations-and-attacks/misc/page-3)
{% endcontent-ref %}

### Configuring

1. Login on `DC02` with the username `Administrator` and password `Welcome01!`.
2. Open the "Active Directory Users and Computers" administration tool on `DC02`.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FHCV9WJ3HHhrkq300sFY3%2Fimage.png?alt=media&#x26;token=68b57427-b249-400f-b7ab-fa662c6788f4" alt=""></div>

3\. Right click on the "Users" directory and select "New" and then "User". Create a user with the name `testreset`.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FsMWBDyRb5NwRkttUY5pk%2Fimage.png?alt=media&#x26;token=51d818da-5a8c-4f0a-8474-77181aec1bd1" alt=""></div>

4\. Fill in the password `Testing123Testing!` and select "Password never expires" and make sure "User must change password at next logon" is not selected.

5\. Login on `FILE01` with the username `Administrator` and password `Welcome01!`.

6\. Open "Windows Explorer" and browse to `C:\Share\IT`.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FXsiGa5WoaPAol8MifVDo%2Fimage.png?alt=media&#x26;token=e577dbe5-bb1c-4f76-b478-8d0145a4e5a0" alt=""></div>

7\. Create a directory "Scripts" and enter the Directory. Then create a new textdocument with the name `Password-reset-transferuser-testscript.ps1` and place the following content inside it:

```
$password = 'Testing123Testing!'
$credentials = New-Object System.Management.Automation.PsCredential("amsterdam\testreset",$password)

Import-module ActiveDirectory
#Generate a 15-character random password.
$Password = -join ((33..126) | Get-Random -Count 15 | ForEach-Object { [char]$ })
$NewPwd = ConvertTo-SecureString $Password -AsPlainText -Force
$user = "sa_transfer_test"
Set-ADAccountPassword $user -NewPassword $NewPwd -Reset -Credential $credentials
#Display userid and new password on the console.
Write-Host $user, $Password
```

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2Feqai94R4K05TmHU1ltlm%2Fimage.png?alt=media&#x26;token=adb3658c-4c9b-419a-a5e0-82ad4a414484" alt=""></div>

8\. Download a couple bogus scripts to the server and place them in the same folder such as:

```
wget https://raw.githubusercontent.com/ruudmens/LazyAdmin/master/Windows%2010/CreateLocalAdminAcc.ps1
wget https://raw.githubusercontent.com/ruudmens/LazyAdmin/master/ActiveDirectory/Add-UsersToGroup.ps1
wget https://raw.githubusercontent.com/ruudmens/LazyAdmin/master/ActiveDirectory/CleanupDisabledUsers.ps1
wget https://raw.githubusercontent.com/ruudmens/LazyAdmin/master/ActiveDirectory/Get-ADUsers.ps1
wget https://raw.githubusercontent.com/ruudmens/LazyAdmin/master/ActiveDirectory/Get-ADComputers.ps1
```

## Attacking

### How it works

During our pentests I often find shares that are accessible for all users and often there are some credentials to be discovered in either configuration files, scripts or Microsoft documents(`.doc`, `.xls`) made to store passwords. Sometimes there even is a NAS that allows null session and read/write on all shares.

### Tools

*

### Executing the attack

The attack is executed from the perspective of already having discovered the IT Share on `FILE01` and having access to it.

{% content-ref url="page-3" %}
[page-3](https://ad-lab.gitbook.io/building-a-windows-ad-lab/vulnerabilities-and-misconfigurations-and-attacks/misc/page-3)
{% endcontent-ref %}

1. For having easy access to look at the share login as `noah` with the password `haoNHasAStrongPassword321!@` on `WS01`.
2. Open File Explorer and browse to `\\file01\Data`.

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FYCM8AnkPX8z73b2UBUwH%2Fimage.png?alt=media&#x26;token=eabac2f6-b7f9-4cef-b255-d5b97cb04946" alt=""></div>

3\. Open the IT directory and then the Script directory.

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FNzvcRLSbbhrapAuKoQ8t%2Fimage.png?alt=media\&token=9e5aa709-c4e2-4089-86ce-14c2d118a1a6)

4\. While looking through the scripts we see that the script `Password-reset-transferuser-testscript` has login credentials saved in the script:

![](https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FuYDCaArJdVLBti3Y34cV%2Fimage.png?alt=media\&token=50aeae85-8b83-414a-ae19-606e03e3ad80)

5\. The password for the user `testreset` probably is `Testing123Testing!`. After reading through the code it seems that its a script to reset the credentials of the user `sa_transfer_test` with the credentials of `testreset`.

We can easily test this by starting a new PowerShell session as this user by opening powershell, then in the taskbar right click on it and shift right clicking on Window PowerShell and then selecting "Runas as different user".

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2F8auP9EPddD3VbP8ONnD0%2Fimage.png?alt=media&#x26;token=a7962e45-0c6f-4011-b1ec-e214731bd926" alt=""></div>

6\. Copy and paste the credentials and click on "OK". A PowerShell window opens, type `whoami` to check if we are running as the `testreset` user:

<div align="left"><img src="https://1033393870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPqGbN7FCY7Xh4OkOtvin%2Fuploads%2FGxTh9tLH0HBkS66ohiZ9%2Fimage.png?alt=media&#x26;token=a12dbce0-183f-493e-9c66-d8b9b6a99754" alt=""></div>

On the following page the ACL's this account has will be abused by resetting a password from another user:

{% content-ref url="../active-directory-attacks/acl-abuses/forcechangepassword" %}
[forcechangepassword](https://ad-lab.gitbook.io/building-a-windows-ad-lab/vulnerabilities-and-misconfigurations-and-attacks/active-directory-attacks/acl-abuses/forcechangepassword)
{% endcontent-ref %}

## Defending

### Recommendations

* Don't save credentials in readable files.
