Skip to content

Commit 9e75866

Browse files
author
Brent Cook
committed
Land rapid7#7738, Add sort by column to services and hosts commands
2 parents 94f62bf + a8f36c2 commit 9e75866

File tree

2 files changed

+20
-4
lines changed
  • lib/msf/ui/console/command_dispatcher
  • spec/lib/msf/ui/console/command_dispatcher

2 files changed

+20
-4
lines changed

lib/msf/ui/console/command_dispatcher/db.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ def cmd_hosts(*args)
360360
onlyup = true
361361
when '-o'
362362
output = args.shift
363+
when '-O'
364+
if (order_by = args.shift.to_i - 1) < 0
365+
print_error('Please specify a column number starting from 1')
366+
return
367+
end
363368
when '-R', '--rhosts'
364369
set_rhosts = true
365370
when '-S', '--search'
@@ -386,6 +391,7 @@ def cmd_hosts(*args)
386391
print_line " -h,--help Show this help information"
387392
print_line " -u,--up Only show hosts which are up"
388393
print_line " -o <file> Send output to a file in csv format"
394+
print_line " -O <column> Order rows by specified column number"
389395
print_line " -R,--rhosts Set RHOSTS from the results of the search"
390396
print_line " -S,--search Search string to filter by"
391397
print_line " -i,--info Change the info of a host"
@@ -425,8 +431,9 @@ def cmd_hosts(*args)
425431
# If we got here, we're searching. Delete implies search
426432
tbl = Rex::Text::Table.new(
427433
{
428-
'Header' => "Hosts",
429-
'Columns' => col_names,
434+
'Header' => "Hosts",
435+
'Columns' => col_names,
436+
'SortIndex' => order_by
430437
})
431438

432439
# Sentinal value meaning all
@@ -586,6 +593,11 @@ def cmd_services(*args)
586593
return
587594
end
588595
output_file = ::File.expand_path(output_file)
596+
when '-O'
597+
if (order_by = args.shift.to_i - 1) < 0
598+
print_error('Please specify a column number starting from 1')
599+
return
600+
end
589601
when '-R', '--rhosts'
590602
set_rhosts = true
591603
when '-S', '--search'
@@ -604,6 +616,7 @@ def cmd_services(*args)
604616
print_line " -r <protocol> Only show [tcp|udp] services"
605617
print_line " -u,--up Only show services which are up"
606618
print_line " -o <file> Send output to a file in csv format"
619+
print_line " -O <column> Order rows by specified column number"
607620
print_line " -R,--rhosts Set RHOSTS from the results of the search"
608621
print_line " -S,--search Search string to filter by"
609622
print_line
@@ -651,8 +664,9 @@ def cmd_services(*args)
651664
col_names = col_search
652665
end
653666
tbl = Rex::Text::Table.new({
654-
'Header' => "Services",
655-
'Columns' => ['host'] + col_names,
667+
'Header' => "Services",
668+
'Columns' => ['host'] + col_names,
669+
'SortIndex' => order_by
656670
})
657671

658672
# Sentinal value meaning all

spec/lib/msf/ui/console/command_dispatcher/db_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@
387387
" -h,--help Show this help information",
388388
" -u,--up Only show hosts which are up",
389389
" -o <file> Send output to a file in csv format",
390+
" -O <column> Order rows by specified column number",
390391
" -R,--rhosts Set RHOSTS from the results of the search",
391392
" -S,--search Search string to filter by",
392393
" -i,--info Change the info of a host",
@@ -462,6 +463,7 @@
462463
" -r <protocol> Only show [tcp|udp] services",
463464
" -u,--up Only show services which are up",
464465
" -o <file> Send output to a file in csv format",
466+
" -O <column> Order rows by specified column number",
465467
" -R,--rhosts Set RHOSTS from the results of the search",
466468
" -S,--search Search string to filter by",
467469
"Available columns: created_at, info, name, port, proto, state, updated_at"

0 commit comments

Comments
 (0)