-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurldump.sh
executable file
·55 lines (51 loc) · 1.21 KB
/
curldump.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
set -eu
usage() {
echo "Usage: $0 <curl options...>" 1>&2
exit 1
}
wait_until_tcp_fin_wait_dismissed() {
while ss -t -n | grep -F -q 'FIN-WAIT'
do
sleep 0.1
done
}
if [ ! -f /.dockerenv ]; then
echo "Note: This script is intended to run within a Docker container." 1>&2
echo "The resulting capture file may contain packets unrelated to the curl command." 1>&2
fi
if [ $# -lt 1 ]; then
usage
fi
cap_file="$(mktemp -u curldump_XXXXXX)"".pcapng"
dumpcap -q -p -w "/tmp/$cap_file" &
pid_dumpcap=$!
while :
do
if [ ! -d /proc/$pid_dumpcap ]; then
echo "Error: dumpcap command exited before creating capture file." 1>&2
exit 1
fi
if [ -e "/tmp/$cap_file" ]; then
break
fi
sleep 0.1
done
sslkeylog_file="$(mktemp -u sslkeylog_XXXXXX)"
SSLKEYLOGFILE="/tmp/$sslkeylog_file" curl "$@" &
pid_curl=$!
wait $pid_curl
wait_until_tcp_fin_wait_dismissed
base_cap_size=$(stat -c '%s' "/tmp/$cap_file")
timeout 10 sh -c "
while :
do
cap_size=\$(stat -c '%s' \"/tmp/$cap_file\")
if [ \"\$cap_size\" -ne $base_cap_size ]; then
break
fi
sleep 0.1
done"
kill -INT $pid_dumpcap
wait $pid_dumpcap
editcap --inject-secrets tls,"/tmp/$sslkeylog_file" "/tmp/$cap_file" "${OUTFILE:-$cap_file}"