-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-Asus-Router-ClientList.ps1
More file actions
149 lines (117 loc) · 5.01 KB
/
Get-Asus-Router-ClientList.ps1
File metadata and controls
149 lines (117 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
.SYNOPSIS
Gets the connected client list from the specified Asus router.
.DESCRIPTION
Gets the connected client list from the specified Asus router
by requesting an authentication token and querying the router's
appGet.cgi interface.
.NOTES
Author: Jonathan Panning <jpann [at] impostr-labs.com>
Created on: 01-18-2024
Last updated: 01-18-2024
.PARAMETER Address
System.String. Specifies the IP address or host name of the router.
.PARAMETER User
System.String. Specifies rhe router's login username.
.PARAMETER Password
System.Security.SecureString. Secure string containing the router's password.
.INPUTS
Does not accept any inputs.
.OUTPUTS
PSObject[]. Returns an object array containing each client's information.
.EXAMPLE
PS> .\Get-Asus-Router-ClientList.ps1 -Address 192.168.1.1 -User admin | Format-Table
Enter Password> *****
type defaultType name nickName ip mac from macRepeat isGateway isWebServer
---- ----------- ---- -------- -- --- ---- --------- --------- -----------
72 10 Computer 192.168.1.13 A4:A0:21:F6:FF:F8 networkmapd 0 0 0
2 2 camera Camera 192.168.1.43 E9:FD:D3:2A:30:4B networkmapd 0 0 0
4 0 Electronics Inc Device 192.168.1.18 C5:AD:B0:A6:DD:40 networkmapd 0 0 0
.EXAMPLE
PS> $Password = Read-Host -AsSecureString
PS> .\Get-Asus-Router-ClientList.ps1 -Address 192.168.1.1 -User admin -Password $Password
| Select name, nickname, ip, mac
| Export-Csv -Path C:\temp\clients.csv -NoTypeInformation
#>
[CmdletBinding()]
[OutputType([System.Management.Automation.PSCustomObject[]])]
Param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]
$Address,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$User,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[SecureString]$Password
)
BEGIN {
function Get-Login-Token {
[OutputType('System.String')]
Param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Address,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$User,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[SecureString]$Password
)
$account = "$($User):$([System.Net.NetworkCredential]::new("""", $Password).Password)"
$string_bytes = $([System.Text.Encoding]::ASCII.GetBytes($account))
$login = [Convert]::ToBase64String($string_bytes)
$postParams = @{
'login_authorization' = $login;
}
# Using this specific User-Agent is required
$headers = @{
'User-Agent' = 'asusrouter-Android-DUTUtil-1.0.0.245';
'Content-Type' = 'application/json';
}
$loginUrl = "http://$($Address)/login.cgi"
$response = Invoke-WebRequest -Uri $loginUrl -Method POST -Body $postParams -Headers $headers
$token = ($response | ConvertFrom-Json).asus_token
Write-Output $token
}
function Get-Client-List {
[OutputType('System.String')]
Param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Address,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$Token
)
$clientListUrl = "http://$($Address)/appGet.cgi"
$postParams = @{
'hook' = "get_clientlist();";
}
# Using this specific User-Agent is required
$headers = @{
'User-Agent' = 'asusrouter-Android-DUTUtil-1.0.0.245';
'Content-Type' = 'application/x-www-form-urlencoded';
'Accept' = "*/*"
}
# Add token cookie
$session = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
$tokenCookie = [System.Net.Cookie]::new('asus_token', $Token)
$session.Cookies.Add($clientListUrl, $tokenCookie)
$clickedItemCookie = [System.Net.Cookie]::new('clickedItem_tab', '0')
$session.Cookies.Add($clientListUrl, $clickedItemCookie)
$response = Invoke-WebRequest -Uri $clientListUrl -Method POST -Body $postParams -Headers $headers -WebSession $session
$clientList = ($response | ConvertFrom-Json).get_clientlist | Select-Object -Property * -ExcludeProperty maclist,ClientAPILevel
$clientList.PSObject.Properties.Value | Write-Output
}
}
PROCESS {
$token = Get-Login-Token -Address $Address -User $User -Password $Password
Write-Verbose "asus_token: $token"
# Get client list
$clientList = Get-Client-List -Address $Address -Token $token
Write-Output $clientList
}