Can't get tcpdump to collect data from Android

I am trying to write a bash script in Ubuntu to install an application on an Android emulator, send random commands to the application using "monkey" and capture all the data using tcpdump. The code:

#!/bin/bash

#store all apks files in array
shopt -s nullglob
packageArray=(*.apk)


function getPackageName()
{
    myResult= aapt dump badging $1 | grep package | awk '{print $2}' | sed   s/name=//g | sed s/\'//g
}

#loop through array installing, testing and capturing data, and uninstalling
for i in "${packageArray[@]}";
do
    :
    myResult=$(getPackageName "$i")

echo "------------------INSTALLING-----------------"

sudo adb install $i
echo "*****************INSTALLED****************************"

echo "*****************TESTING****************************"

#-------THESE COMMANDS ARE THE TROUBLE-------

(sudo -i xterm -e "tcpdump src 10.0.2.11 -vvv >   /home/seed/Documents/autoTcpLogs/$myResult.pcap" &
sudo -i xterm -e "adb shell monkey -p $myResult -v 500")
echo "------------------DONE TESTING-----------------"

sudo adb uninstall $myResult
echo "*****************PACKAGE UNINSTALLED****************************"

done

Problem: I need a good way to close tcpdump after the monkey has finished sending 500 random commands. I tried using the KILL command in several ways, but it doesn't seem to be the trick.

+4
source share
1 answer

Consider the following example:

#!/bin/bash

sudo -- tcpdump > /dev/null &
SUDO_TCPDUMP_PID=$!
echo "Waiting 3 seconds"
sleep 3;
echo "3 seconds elapsed"
sudo -- setsid kill -TERM "${SUDO_TCPDUMP_PID}"

( ): setsid, , sudo (. sudo ).

PID sudo tcpdump ... (sudo pid ) SUDO_TCPDUMP_PID, kill:

$ ./tcp.sh
Waiting 3 seconds
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlp2s0, link-type EN10MB (Ethernet), capture size 262144 bytes
3 seconds elapsed
0 packets captured
2 packets received by filter
0 packets dropped by kernel
$
+1

Source: https://habr.com/ru/post/1649961/


All Articles