@@ -68,6 +68,9 @@ class Core
68
68
@@search_opts = Rex ::Parser ::Arguments . new (
69
69
"-h" => [ false , "Help banner." ] )
70
70
71
+ @@go_pro_opts = Rex ::Parser ::Arguments . new (
72
+ "-h" => [ false , "Help banner." ] )
73
+
71
74
# The list of data store elements that cannot be set when in defanged
72
75
# mode.
73
76
DefangedProhibitedDataStoreElements = [ "MsfModulePaths" ]
@@ -82,6 +85,7 @@ def commands
82
85
"connect" => "Communicate with a host" ,
83
86
"color" => "Toggle color" ,
84
87
"exit" => "Exit the console" ,
88
+ "go_pro" => "Launch Metasploit web GUI" ,
85
89
"help" => "Help menu" ,
86
90
"info" => "Displays information about one or more module" ,
87
91
"irb" => "Drop into irb scripting mode" ,
@@ -133,6 +137,17 @@ def name
133
137
"Core"
134
138
end
135
139
140
+ # Indicates the base dir where Metasploit Framework is installed.
141
+ def msfbase_dir
142
+ base = __FILE__
143
+ while File . symlink? ( base )
144
+ base = File . expand_path ( File . readlink ( base ) , File . dirname ( base ) )
145
+ end
146
+ File . expand_path (
147
+ File . join ( File . dirname ( base ) , ".." , ".." , ".." , ".." , ".." )
148
+ )
149
+ end
150
+
136
151
def cmd_color_help
137
152
print_line "Usage: color <'true'|'false'|'auto'>"
138
153
print_line
@@ -340,13 +355,28 @@ def cmd_banner_help
340
355
#
341
356
def cmd_banner ( *args )
342
357
banner = "%cya" + Banner . to_s + "%clr\n \n "
358
+
359
+ if is_apt
360
+ content = [
361
+ "Large pentest? List, sort, group, tag and search your hosts and services\n in Metasploit Pro -- type 'go_pro' to launch it now." ,
362
+ "Frustrated with proxy pivoting? Upgrade to layer-2 VPN pivoting with\n Metasploit Pro -- type 'go_pro' to launch it now." ,
363
+ "Save your shells from AV! Upgrade to advanced AV evasion using dynamic\n exe templates with Metasploit Pro -- type 'go_pro' to launch it now." ,
364
+ "Easy phishing: Set up email templates, landing pages and listeners\n in Metasploit Pro’s wizard -- type 'go_pro' to launch it now." ,
365
+ "Using notepad to track pentests? Have Metasploit Pro report on hosts,\n services, sessions and evidence -- type 'go_pro' to launch it now." ,
366
+ "Tired of typing ‘set RHOSTS’? Click & pwn with Metasploit Pro\n -- type 'go_pro' to launch it now."
367
+ ]
368
+ banner << content . sample # Ruby 1.9-ism!
369
+ banner << "\n \n "
370
+ end
371
+
343
372
banner << " =[ %yelmetasploit v#{ Msf ::Framework ::Version } [core:#{ Msf ::Framework ::VersionCore } api:#{ Msf ::Framework ::VersionAPI } ]%clr\n "
344
373
banner << "+ -- --=[ "
345
374
banner << "#{ framework . stats . num_exploits } exploits - #{ framework . stats . num_auxiliary } auxiliary - #{ framework . stats . num_post } post\n "
346
375
banner << "+ -- --=[ "
347
376
348
377
oldwarn = nil
349
378
avdwarn = nil
379
+
350
380
banner << "#{ framework . stats . num_payloads } payloads - #{ framework . stats . num_encoders } encoders - #{ framework . stats . num_nops } nops\n "
351
381
if ( ::Msf ::Framework ::RepoRevision . to_i > 0 and ::Msf ::Framework ::RepoUpdatedDate )
352
382
tstamp = ::Msf ::Framework ::RepoUpdatedDate . strftime ( "%Y.%m.%d" )
@@ -2575,7 +2605,124 @@ def option_values_target_ports
2575
2605
return res
2576
2606
end
2577
2607
2578
- protected
2608
+ def cmd_go_pro_help
2609
+ print_line "Usage: go_pro"
2610
+ print_line
2611
+ print_line "Launch the Metasploit web GUI"
2612
+ print_line
2613
+ end
2614
+
2615
+ def cmd_go_pro ( *args )
2616
+ @@go_pro_opts . parse ( args ) do |opt , idx , val |
2617
+ case opt
2618
+ when "-h"
2619
+ cmd_go_pro_help
2620
+ return false
2621
+ end
2622
+ end
2623
+ unless is_apt
2624
+ print_line " This command is only available on deb package installations,"
2625
+ print_line " such as Kali Linux."
2626
+ return false
2627
+ end
2628
+ unless is_metasploit_debian_package_installed
2629
+ print_warning "You need to install the 'metasploit' package first."
2630
+ print_warning "Type 'apt-get install -y metasploit' to do this now, then exit"
2631
+ print_warning "and restart msfconsole to try again."
2632
+ return false
2633
+ end
2634
+ # If I've gotten this far, I know that this is apt-installed, the
2635
+ # metasploit package is here, and I'm ready to rock.
2636
+ if is_metasploit_service_running
2637
+ launch_metasploit_browser
2638
+ else
2639
+ print_status "Starting the Metasploit services. This can take a little time."
2640
+ start_metasploit_service
2641
+ select ( nil , nil , nil , 3 )
2642
+ if is_metasploit_service_running
2643
+ launch_metasploit_browser
2644
+ else
2645
+ print_error "Metasploit services aren't running. Type 'service start metasploit' and try again."
2646
+ end
2647
+ end
2648
+ return true
2649
+ end
2650
+
2651
+ protected
2652
+
2653
+ #
2654
+ # Go_pro methods -- these are used to start and connect to
2655
+ # Metasploit Community / Pro.
2656
+ #
2657
+
2658
+ # Note that this presumes a default port.
2659
+ def launch_metasploit_browser
2660
+ cmd = "/usr/bin/xdg-open"
2661
+ unless ::File . executable_real? cmd
2662
+ print_warning "Can't figure out your default browser, please visit https://localhost:3790"
2663
+ print_warning "to start Metasploit Community / Pro."
2664
+ return false
2665
+ end
2666
+ svc_log = File . expand_path ( File . join ( msfbase_dir , ".." , "engine" , "prosvc_stdout.log" ) )
2667
+ return unless ::File . readable_real? svc_log
2668
+ really_started = false
2669
+ # This method is a little lame but it's a short enough file that it
2670
+ # shouldn't really matter that we open and close it a few times.
2671
+ timeout = 0
2672
+ until really_started
2673
+ select ( nil , nil , nil , 3 )
2674
+ log_data = ::File . open ( svc_log , "rb" ) { |f | f . read f . stat . size }
2675
+ really_started = log_data =~ /^\[ \* \] Ready/ # This is webserver ready
2676
+ if really_started
2677
+ print_line
2678
+ print_good "Metasploit Community / Pro is up and running, connecting now."
2679
+ print_good "If this is your first time connecting, you will be presented with"
2680
+ print_good "a self-signed certificate warning. Accept it to create a new user."
2681
+ select ( nil , nil , nil , 7 )
2682
+ browser_pid = ::Process . spawn ( cmd , "https://localhost:3790" )
2683
+ ::Process . detach ( browser_pid )
2684
+ elsif timeout >= 200 # 200 * 3 seconds is 10 minutes and that is tons of time.
2685
+ print_line
2686
+ print_warning "For some reason, Community / Pro didn't start in a timely fashion."
2687
+ print_warning "You might want to restart the Metasploit services by typing"
2688
+ print_warning "'service metasploit restart' . Sorry it didn't work out."
2689
+ return false
2690
+ else
2691
+ print "."
2692
+ timeout += 1
2693
+ end
2694
+ end
2695
+ end
2696
+
2697
+ def start_metasploit_service
2698
+ cmd = "/usr/sbin/service"
2699
+ return unless ::File . executable_real? cmd
2700
+ %x{#{ cmd } metasploit start} . each_line do |line |
2701
+ print_status line . chomp
2702
+ end
2703
+ end
2704
+
2705
+ def is_metasploit_service_running
2706
+ cmd = "/usr/sbin/service"
2707
+ system ( cmd , "metasploit" , "status" ) # Both running returns true, otherwise, false.
2708
+ end
2709
+
2710
+ def is_metasploit_debian_package_installed
2711
+ cmd = "/usr/bin/dpkg"
2712
+ return unless ::File . executable_real? cmd
2713
+ installed_packages = %x{#{ cmd } -l 'metasploit'}
2714
+ installed_packages . each_line do |line |
2715
+ if line =~ /^.i metasploit / # Yes, trailing space
2716
+ return true
2717
+ end
2718
+ end
2719
+ return false
2720
+ end
2721
+
2722
+ # Determines if this is an apt-based install
2723
+ def is_apt
2724
+ File . exists? ( File . expand_path ( File . join ( msfbase_dir , '.apt' ) ) )
2725
+ end
2579
2726
2580
2727
#
2581
2728
# Module list enumeration
0 commit comments