mirror of
https://github.com/e-fin/ADWS-BOF
synced 2026-06-23 09:33:17 +00:00
96 lines
3.1 KiB
Plaintext
96 lines
3.1 KiB
Plaintext
beacon_command_register(
|
|
"adwsldapsearch",
|
|
"BOF - Perform LDAP search with ADWS.",
|
|
"Usage:
|
|
adwsldapsearch --ip 10.0.0.1 --domain example.com --username user --password password --query (objectClass=user) --attrs sAMAccountName,description --dn DC=lab,DC=local
|
|
|
|
Arguments:
|
|
--ip (OPTIONAL) IP address of server running ADWS, typically domain controller.
|
|
--domain Domain Name of the Domain you are querying.
|
|
--username (OPTIONAL)Username to use for authentication, use --domain to specify user domain.
|
|
--password (OPTIONAL) Password to use for authentication. (OPTIONAL)
|
|
--query LDAP Query, CNA handles spaces in arguments, dont need to use quotes.
|
|
--attrs (OPTIONAL)Attributes for LDAP query, provide none to choose *
|
|
--dn Search Base for the LDAP Query
|
|
|
|
Notes:
|
|
- Do not wrap any arguments in quotes.
|
|
- Arguments can be placed in any order.
|
|
- Providing no username or password will use current access token.
|
|
- Providing no IP will automatically determine DC IP.
|
|
");
|
|
|
|
alias adwsldapsearch {
|
|
local('$handle $data $path $ip $dn $username $password $attributes $query $dn $domain $args $i $opt $val $j');
|
|
|
|
$path = script_resource("adwsldap.x64.o");
|
|
$handle = openf($path);
|
|
if ($handle is $null) {
|
|
berror($1, "Could not open file: " . $path);
|
|
return;
|
|
}
|
|
$data = readb($handle, lof($path));
|
|
closef($handle);
|
|
if (strlen($data) == 0) {
|
|
berror($1, "Failed to load BOF — check path");
|
|
return;
|
|
}
|
|
|
|
if (size(@_) == 1) {
|
|
berror($1, beacon_command_detail("adwsldapsearch"));
|
|
return;
|
|
}
|
|
|
|
$ip = "NULL";
|
|
$domain = "";
|
|
$username = "NULL";
|
|
$password = "NULL";
|
|
$query = "";
|
|
$attributes = "";
|
|
$dn = "";
|
|
|
|
$i = 1;
|
|
while ($i < size(@_)) {
|
|
$opt = @_[$i];
|
|
|
|
# collect all tokens until the next -- flag as the value
|
|
$val = "";
|
|
$j = $i + 1;
|
|
while ($j <= size(@_) - 1) {
|
|
if (left(@_[$j], 2) eq "--") {
|
|
break;
|
|
}
|
|
if (strlen($val) > 0) { $val = $val . " "; }
|
|
$val = $val . @_[$j];
|
|
$j++;
|
|
}
|
|
$i = $j;
|
|
|
|
if ($opt eq "--ip") {
|
|
$ip = $val;
|
|
} else if ($opt eq "--domain") {
|
|
$domain = $val;
|
|
} else if ($opt eq "--username") {
|
|
$username = $val;
|
|
} else if ($opt eq "--password") {
|
|
$password = $val;
|
|
} else if ($opt eq "--query") {
|
|
$query = $val;
|
|
} else if ($opt eq "--attrs") {
|
|
$attributes = $val;
|
|
} else if ($opt eq "--dn") {
|
|
$dn = $val;
|
|
} else {
|
|
berror($1, "Unknown argument: " . $opt);
|
|
return;
|
|
}
|
|
}
|
|
|
|
#if ($ip eq "") { berror($1, "Missing --ip"); return; }
|
|
if ($domain eq "") { berror($1, "Missing --domain"); return; }
|
|
if ($query eq "") { berror($1, "Missing --query"); return; }
|
|
if ($dn eq "") { berror($1, "Missing --dn"); return; }
|
|
|
|
$args = bof_pack($1, "zzzzzzz", $ip, $domain, $username, $password, $query, $attributes,$dn);
|
|
beacon_inline_execute($1, $data, "go", $args);
|
|
} |