enumhandles.cna 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # author REDMED-X
  2. beacon_command_register(
  3. "enumhandles", "Find process and thread handle types between processes.",
  4. "INFO:\nFind process and thread handle types between processes.\n\nOPTIONS:\n[all]: list all processes with handles to all other processes\n[h2p]: list all processes that have a handle to a specific process\n[p2h]: list handles from a specific process to all other processes\n\nHandle Query Options:\n[proc]: search for PROCESS type handles\n[thread]: search for THREAD type handles\n\nTargeted Search Options:\n[<pid>]: for both the [h2p] and [p2h] search options, specify the PID of the process your interested in.\n\n" .
  5. "USAGE:\nenumhandles all <proc | thread>\nenumhandles h2p <proc | thread> <pid>\nenumhandles p2h <proc | thread> <pid>\n\n");
  6. alias enumhandles {
  7. $bid = $1;
  8. $search = $2;
  9. $query = $3;
  10. $pid = $4;
  11. if ($search eq "") {
  12. berror($bid, "Please specify one of the following seach options: all | h2p | p2h\n");
  13. return;
  14. }
  15. if ($search eq "all" || $search eq "h2p" || $search eq "p2h") {
  16. if ($query eq "") {
  17. berror($bid, "Please specify one of the following handle types to search for: proc | thread\n");
  18. return;
  19. }
  20. if ($query eq "proc" || $query eq "thread") {
  21. if ($search eq "h2p" && $pid eq "" ) {
  22. berror($bid, "Please specify the pid to target a specific process.\n");
  23. return;
  24. }
  25. if ($search eq "p2h" && $pid eq "" ) {
  26. berror($bid, "Please specify the pid to target a specific process.\n");
  27. return;
  28. }
  29. }
  30. else {
  31. berror($bid, "This handle type isn't supported. Please specify one of the following handle types to search for: proc | thread\n");
  32. return;
  33. }
  34. }
  35. else {
  36. berror($bid, "This option isn't supported. Please specify one of the following seach options: all | h2p | p2h\n");
  37. return;
  38. }
  39. # Read in the right BOF file
  40. $handle = openf(script_resource("enumhandles.o"));
  41. $data = readb($handle, -1);
  42. closef($handle);
  43. # Pack our arguments
  44. if ($pid eq "") {
  45. $arg_data = bof_pack($bid, "zz", $search, $query);
  46. }
  47. else {
  48. $arg_data = bof_pack($bid, "zzi", $search, $query, $pid);
  49. }
  50. blog($bid, "Tasked to enumerate handles..");
  51. beacon_inline_execute($bid, $data, "go", $arg_data);
  52. }