@@ -450,6 +450,25 @@ def stdapi_sys_process_get_processes_via_proc(request, response):
450
450
response += tlv_pack (TLV_TYPE_PROCESS_GROUP , pgroup )
451
451
return ERROR_SUCCESS , response
452
452
453
+ def stdapi_sys_process_get_processes_via_ps (request , response ):
454
+ ps_args = ['ps' , 'ax' , '-w' , '-o' , 'pid,ppid,user,command' ]
455
+ proc_h = subprocess .Popen (ps_args , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
456
+ ps_output = proc_h .stdout .read ()
457
+ ps_output = ps_output .split ('\n ' )
458
+ ps_output .pop (0 )
459
+ for process in ps_output :
460
+ process = process .split ()
461
+ if len (process ) < 4 :
462
+ break
463
+ pgroup = ''
464
+ pgroup += tlv_pack (TLV_TYPE_PID , int (process [0 ]))
465
+ pgroup += tlv_pack (TLV_TYPE_PARENT_PID , int (process [1 ]))
466
+ pgroup += tlv_pack (TLV_TYPE_USER_NAME , process [2 ])
467
+ pgroup += tlv_pack (TLV_TYPE_PROCESS_NAME , os .path .basename (process [3 ]))
468
+ pgroup += tlv_pack (TLV_TYPE_PROCESS_PATH , ' ' .join (process [3 :]))
469
+ response += tlv_pack (TLV_TYPE_PROCESS_GROUP , pgroup )
470
+ return ERROR_SUCCESS , response
471
+
453
472
def stdapi_sys_process_get_processes_via_windll (request , response ):
454
473
TH32CS_SNAPPROCESS = 2
455
474
PROCESS_QUERY_INFORMATION = 0x0400
@@ -530,6 +549,8 @@ def stdapi_sys_process_get_processes(request, response):
530
549
return stdapi_sys_process_get_processes_via_proc (request , response )
531
550
elif has_windll :
532
551
return stdapi_sys_process_get_processes_via_windll (request , response )
552
+ else :
553
+ return stdapi_sys_process_get_processes_via_ps (request , response )
533
554
return ERROR_FAILURE , response
534
555
535
556
@meterpreter .register_function
0 commit comments