0

I am trying to dump the partitions of Android devices with netcat. I have created 3 bash scripts for supporting the process. I have trouble on the second which to dumpt the specific partition through netcat. On the command line I used to type the following commands:

  1. adb shell
  2. su
  3. (on root) dd if=/dev/block/mmcblk0 | /sdcard/nc -l -p 8888

Based on the commands above, I have tried to make a bash script with detail below:

   #!/bin/bash
   adb shell "su
   dd if=/dev/block/mmcblk0 | /dev/examiner/nc -l -p 8888"

But the result is text file with zero size. I have tried to change the quotation mark for identifying the variable, but the result was still the same.

Thanks in advance.

5
  • I guess /dev/examiner it's nc's path in the Ubuntu filesystem? That would explain that
    – kos
    Aug 27, 2015 at 12:23
  • No. /dev/examiner/nc is the path of nc application on the Android device. I have tried to put the nc file in the sdcard. But the result is still the same.
    – aph4nc
    Aug 27, 2015 at 12:24
  • Ah, and anyway reading the question better it wouldn't have explained that at all. However I think that the problem is that the command is executed in the unprivileged adb shell, and not in the shell spawned by su, which leads to the execution of the pipe without root privileges. Try adb shell "su -c 'dd if=/dev/block/mmcblk0 | /dev/examiner/nc -l -p 8888'''
    – kos
    Aug 27, 2015 at 12:43
  • It works! Thanks heaps mate! I really appreciate it!
    – aph4nc
    Aug 27, 2015 at 12:52
  • Glad that it helped :) I'll make an answer out of my comment then, please accept it
    – kos
    Aug 27, 2015 at 12:54

1 Answer 1

1
#!/bin/bash
adb shell "su
dd if=/dev/block/mmcblk0 | /dev/examiner/nc -l -p 8888"

The problem is that this way the pipe is executed in the unprivileged adb shell, and not in the root shell spawned by su; this leads to the pipe being executed without root privileges and to the 0-lenght file (probably due to the if command failing to read a block device without root privileges).

Run the command directly into the root shell spawned by su by using su's -c option, which allows to run a command directly into the spawned shell:

#!/bin/bash
adb shell "su -c 'dd if=/dev/block/mmcblk0 | /dev/examiner/nc -l -p 8888'"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .