Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ipconfig in php meterpreter #720

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions php/meterpreter/ext_server_stdapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
##
define("TLV_TYPE_HOST_NAME", TLV_META_TYPE_STRING | 1400);
define("TLV_TYPE_PORT", TLV_META_TYPE_UINT | 1401);
define("TLV_TYPE_INTERFACE_MTU", TLV_META_TYPE_UINT | 1402);

define("TLV_TYPE_SUBNET", TLV_META_TYPE_RAW | 1420);
define("TLV_TYPE_NETMASK", TLV_META_TYPE_RAW | 1421);
Expand Down Expand Up @@ -1267,6 +1268,40 @@ function stdapi_registry_set_value($req, &$pkt) {
}
}

if (!function_exists('stdapi_net_config_get_interfaces')) {
if (is_callable('net_get_interfaces')) {
register_command('stdapi_net_config_get_interfaces', COMMAND_ID_STDAPI_NET_CONFIG_GET_INTERFACES);
}
function stdapi_net_config_get_arp_interfaces($req, &$pkt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be: stdapi_net_config_get_interfaces

if (!is_callable('net_get_interfaces')) {
return ERROR_FAILURE;
}
$content = net_get_interfaces();
if ($content === false) {
return ERROR_FAILURE;
}
foreach($content as $iface_name => $iface_data) {
my_print("Info for $iface_name: " . json_encode($iface_data));
$iface_tlv = tlv_pack(create_tlv(TLV_TYPE_MAC_NAME, $iface_name));
if (array_key_exists('mac', $iface_data)) {
$iface_tlv .= tlv_pack(create_tlv(TLV_TYPE_MAC_ADDRESS, pack("H*", str_replace(':', '', $iface_data['mac']))));
}
if (array_key_exists('mtu', $iface_data)) {
$iface_tlv .= tlv_pack(create_tlv(TLV_TYPE_INTERFACE_MTU, $iface_data['mtu']));
}
if (!array_key_exists('unicast', $iface_data)) {
foreach($iface_data['unicast'] as $iface_network) {
$iface_tlv .= tlv_pack(create_tlv(TLV_TYPE_IP, inet_pton($iface_network['address'])));
$iface_tlv .= tlv_pack(create_tlv(TLV_TYPE_NETMASK, $iface_network['netmask']));
}
}
packet_add_tlv($pkt, create_tlv(TLV_TYPE_NETWORK_INTERFACE, $iface_tlv));
}

return ERROR_SUCCESS;
}
}

if (!function_exists('stdapi_net_config_get_arp_table')) {
if (is_linux()) {
register_command('stdapi_net_config_get_arp_table', COMMAND_ID_STDAPI_NET_CONFIG_GET_ARP_TABLE);
Expand Down
Loading