/usr/sbin
NameSizeModeActions
aa-load396800755editdlrm
aa-remove-unknown32250755editdlrm
aa-status400000755editdlrm
aa-teardown1370755editdlrm
accessdb149040755editdlrm
acpid539200755editdlrm
add-shell10530755editdlrm
addgnupghome30750755editdlrm
addgroup551910755editdlrm
adduser551910755editdlrm
agetty609920755editdlrm
apparmor_parser16298480755editdlrm
apparmor_status400000755editdlrm
applygnupgdefaults22170755editdlrm
argdist-bpfcc368620755editdlrm
arpd269600755editdlrm
arptables2244240755editdlrm
arptables-nft2244240755editdlrm
arptables-nft-restore2244240755editdlrm
arptables-nft-save2244240755editdlrm
arptables-restore2244240755editdlrm
arptables-save2244240755editdlrm
badblocks351440755editdlrm
bashreadline-bpfcc23800755editdlrm
bashreadline.bt6980755editdlrm
bcache-super-show146480755editdlrm
bindsnoop-bpfcc163460755editdlrm
biolatency-bpfcc113650755editdlrm
biolatency-kp.bt6640755editdlrm
biolatency.bt6810755editdlrm
biolatpcts-bpfcc102480755editdlrm
biopattern-bpfcc39570755editdlrm
biosdecode278560755editdlrm
biosnoop-bpfcc108330755editdlrm
biosnoop.bt11480755editdlrm
biostacks.bt9150755editdlrm
biotop-bpfcc95670755editdlrm
bitesize-bpfcc11660755editdlrm
bitesize.bt5670755editdlrm
blkdeactivate163510755editdlrm
blkdiscard229120755editdlrm
blkid557200755editdlrm
blkzone352000755editdlrm
blockdev352000755editdlrm
bpflist-bpfcc26010755editdlrm
bpftool16220755editdlrm
bridge1110960755editdlrm
btrfsdist-bpfcc66270755editdlrm
btrfsslower-bpfcc99850755editdlrm
cachestat-bpfcc65310755editdlrm
cachetop-bpfcc93670755editdlrm
cache_check14305680755editdlrm
cache_dump14305680755editdlrm
cache_metadata_size14305680755editdlrm
cache_repair14305680755editdlrm
cache_restore14305680755editdlrm
cache_writeback14305680755editdlrm
capable-bpfcc84770755editdlrm
capable.bt19260755editdlrm
capsh584560755editdlrm
cfdisk970080755editdlrm
cgdisk1704800755editdlrm
chcpu311040755editdlrm
chgpasswd597200755editdlrm
chmem352000755editdlrm
chpasswd557360755editdlrm
chronyd3062320755editdlrm
chroot394320755editdlrm
cobjnew-bpfcc530755editdlrm
compactsnoop-bpfcc113690755editdlrm
cpgr496080755editdlrm
cppw496080755editdlrm
cpudist-bpfcc70130755editdlrm
cpuunclaimed-bpfcc149380755editdlrm
cpuwalk.bt4970755editdlrm
criticalstat-bpfcc86070755editdlrm
cron600800755editdlrm
cryptdisks_start15440755editdlrm
cryptdisks_stop8440755editdlrm
cryptsetup2313200755editdlrm
ctrlaltdel147200755editdlrm
dbslower-bpfcc73910755editdlrm
dbstat-bpfcc37900755editdlrm
dcb824480755editdlrm
dcsnoop-bpfcc41260755editdlrm
dcsnoop.bt12610755editdlrm
dcstat-bpfcc38590755editdlrm
deadlock-bpfcc209430755editdlrm
debugfs2312880755editdlrm
delgroup189770755editdlrm
deluser189770755editdlrm
depmod1743280755editdlrm
devlink1544800755editdlrm
dhcpcd4048880755editdlrm
dirtop-bpfcc85680755editdlrm
dmeventd515920755editdlrm
dmidecode1384960755editdlrm
dmsetup1751600755editdlrm
dmstats1751600755editdlrm
dosfsck802640755editdlrm
dosfslabel393040755editdlrm
dpkg-preconfigure43560755editdlrm
dpkg-reconfigure45360755editdlrm
drsnoop-bpfcc68890755editdlrm
dumpe2fs351360755editdlrm
e2freefrag187440755editdlrm
e2fsck3730800755editdlrm
e2image433280755editdlrm
e2label1132160755editdlrm
e2mmpstatus351360755editdlrm
e2scrub72940755editdlrm
e2scrub_all53940755editdlrm
e2undo228400755editdlrm
e4crypt311040755editdlrm
e4defrag351280755editdlrm
ebtables2244240755editdlrm
ebtables-nft2244240755editdlrm
ebtables-nft-restore2244240755editdlrm
ebtables-nft-save2244240755editdlrm
ebtables-restore2244240755editdlrm
ebtables-save2244240755editdlrm
ebtables-translate2244240755editdlrm
era_check14305680755editdlrm
era_dump14305680755editdlrm
era_invalidate14305680755editdlrm
era_restore14305680755editdlrm
ethtool6673200755editdlrm
execsnoop-bpfcc100590755editdlrm
execsnoop.bt9280755editdlrm
exitsnoop-bpfcc96460755editdlrm
ext4dist-bpfcc66830755editdlrm
ext4slower-bpfcc99480755editdlrm
faillock228480755editdlrm
fatlabel393040755editdlrm
fdisk1171680755editdlrm
filefrag187600755editdlrm
filegone-bpfcc57760755editdlrm
filelife-bpfcc65280755editdlrm
fileslower-bpfcc73720755editdlrm
filetop-bpfcc64990755editdlrm
findfs147200755editdlrm
fixparts598800755editdlrm
fsadm245800755editdlrm
fsck434400755editdlrm
fsck.btrfs11850755editdlrm
fsck.cramfs311680755editdlrm
fsck.ext23730800755editdlrm
fsck.ext33730800755editdlrm
fsck.ext43730800755editdlrm
fsck.fat802640755editdlrm
fsck.minix557120755editdlrm
fsck.msdos802640755editdlrm
fsck.vfat802640755editdlrm
fsck.xfs25660755editdlrm
fsfreeze147200755editdlrm
fstab-decode146480755editdlrm
fstrim433920755editdlrm
funccount-bpfcc129810755editdlrm
funcinterval-bpfcc55900755editdlrm
funclatency-bpfcc115490755editdlrm
funcslower-bpfcc106300755editdlrm
gdisk2032480755editdlrm
genl1234720755editdlrm
getcap146480755editdlrm
gethostlatency-bpfcc39140755editdlrm
gethostlatency.bt12220755editdlrm
getpcaps146480755editdlrm
getty609920755editdlrm
groupadd728400755editdlrm
groupdel644240755editdlrm
groupmems597440755editdlrm
groupmod727440755editdlrm
grpck597200755editdlrm
grpconv513680755editdlrm
grpunconv513680755editdlrm
grub-bios-setup9815520755editdlrm
grub-install12258240755editdlrm
grub-macbless9691280755editdlrm
grub-mkconfig88400755editdlrm
grub-mkdevicemap723840755editdlrm
grub-probe9775760755editdlrm
grub-reboot48410755editdlrm
grub-set-default35560755editdlrm
halt15013040755editdlrm
hardirqs-bpfcc70190755editdlrm
hdparm1427760755editdlrm
iconvconfig352960755editdlrm
init1008160755editdlrm
inject-bpfcc164450755editdlrm
insmod1743280755editdlrm
install-sgmlcatalog45510755editdlrm
installkernel26590755editdlrm
integritysetup686720755editdlrm
invoke-rc.d165170755editdlrm
ip7729200755editdlrm
ip6tables2244240755editdlrm
ip6tables-apply70520755editdlrm
ip6tables-legacy951760755editdlrm
ip6tables-legacy-restore951760755editdlrm
ip6tables-legacy-save951760755editdlrm
ip6tables-nft2244240755editdlrm
ip6tables-nft-restore2244240755editdlrm
ip6tables-nft-save2244240755editdlrm
ip6tables-restore2244240755editdlrm
ip6tables-restore-translate2244240755editdlrm
ip6tables-save2244240755editdlrm
ip6tables-translate2244240755editdlrm
iptables2244240755editdlrm
iptables-apply70520755editdlrm
iptables-legacy951760755editdlrm
iptables-legacy-restore951760755editdlrm
iptables-legacy-save951760755editdlrm
iptables-nft2244240755editdlrm
iptables-nft-restore2244240755editdlrm
iptables-nft-save2244240755editdlrm
iptables-restore2244240755editdlrm
iptables-restore-translate2244240755editdlrm
iptables-save2244240755editdlrm
iptables-translate2244240755editdlrm
irqbalance602720755editdlrm
irqbalance-ui393040755editdlrm
iscsi-iname187440755editdlrm
iscsiadm3793200755editdlrm
iscsid2934320755editdlrm
iscsistart2810800755editdlrm
iscsi_discovery52930755editdlrm
isosize147200755editdlrm
iucode-tool556400755editdlrm
iucode_tool556400755editdlrm
javacalls-bpfcc550755editdlrm
javaflow-bpfcc540755editdlrm
javagc-bpfcc520755editdlrm
javaobjnew-bpfcc560755editdlrm
javastat-bpfcc540755editdlrm
javathreads-bpfcc570755editdlrm
kbdrate187520755editdlrm
killall5268560755editdlrm
killsnoop-bpfcc45540755editdlrm
killsnoop.bt8730755editdlrm
klockstat-bpfcc133560755editdlrm
kpartx431760755editdlrm
kvmexit-bpfcc114610755editdlrm
ldattach270080755editdlrm
ldconfig3870755editdlrm
ldconfig.real10512800755editdlrm
llcstat-bpfcc45840755editdlrm
loads.bt11270755editdlrm
locale-gen43160755editdlrm
logrotate965040755editdlrm
logsave144960755editdlrm
losetup763040755editdlrm
lsmod1743280755editdlrm
luksformat34010755editdlrm
lvchange31567120755editdlrm
lvconvert31567120755editdlrm
lvcreate31567120755editdlrm
lvdisplay31567120755editdlrm
lvextend31567120755editdlrm
lvm31567120755editdlrm
lvmconfig31567120755editdlrm
lvmdiskscan31567120755editdlrm
lvmdump103640755editdlrm
lvmpolld2416320755editdlrm
lvmsadc31567120755editdlrm
lvmsar31567120755editdlrm
lvreduce31567120755editdlrm
lvremove31567120755editdlrm
lvrename31567120755editdlrm
lvresize31567120755editdlrm
lvs31567120755editdlrm
lvscan31567120755editdlrm
lxc5890755editdlrm
lxd5890755editdlrm
make-bcache229120755editdlrm
mdadm6371440755editdlrm
mdflush-bpfcc22950755editdlrm
mdflush.bt7750755editdlrm
mdmon2650160755editdlrm
memleak-bpfcc212980755editdlrm
mkdosfs520480755editdlrm
mke2fs1337520755editdlrm
mkfs147200755editdlrm
mkfs.bfs229120755editdlrm
mkfs.btrfs5737520755editdlrm
mkfs.cramfs351440755editdlrm
mkfs.ext21337520755editdlrm
mkfs.ext31337520755editdlrm
mkfs.ext41337520755editdlrm
mkfs.fat520480755editdlrm
mkfs.minix434080755editdlrm
mkfs.msdos520480755editdlrm
mkfs.ntfs679760755editdlrm
mkfs.vfat520480755editdlrm
mkfs.xfs4495280755editdlrm
mkhomedir_helper228720755editdlrm
mkinitramfs157620755editdlrm
mklost+found146480755editdlrm
mkntfs679760755editdlrm
mkswap515920755editdlrm
ModemManager21655760755editdlrm
modinfo1743280755editdlrm
modprobe1743280755editdlrm
mount.fuse187360755editdlrm
mount.fuse3187360755editdlrm
mount.lowntfs-3g1218320755editdlrm
mount.ntfs1628240755editdlrm
mount.ntfs-3g1628240755editdlrm
mountsnoop-bpfcc149680755editdlrm
mpathpersist319600755editdlrm
multipath351280755editdlrm
multipathc187440755editdlrm
multipathd1458800755editdlrm
mysqld554679440755editdlrm
mysqld_qslower-bpfcc31250755editdlrm
naptime.bt10350755editdlrm
needrestart410920755editdlrm
netplan8020755editdlrm
netqtop-bpfcc57250755editdlrm
newusers890480755editdlrm
nfnl_osf187360755editdlrm
nfsdist-bpfcc50680755editdlrm
nfsslower-bpfcc139390755editdlrm
nft268560755editdlrm
nginx13141680755editdlrm
nodegc-bpfcc520755editdlrm
nodestat-bpfcc540755editdlrm
nologin146400755editdlrm
ntfsclone515920755editdlrm
ntfscp311040755editdlrm
ntfslabel229120755editdlrm
ntfsresize638880755editdlrm
ntfsundelete515920755editdlrm
offcputime-bpfcc137790755editdlrm
offwaketime-bpfcc156760755editdlrm
on_ac_power37880755editdlrm
oomkill-bpfcc20840755editdlrm
oomkill.bt11980755editdlrm
opensnoop-bpfcc145810755editdlrm
opensnoop.bt9530755editdlrm
overlayroot-chroot25100755editdlrm
ownership147920755editdlrm
pam-auth-update214650755editdlrm
pam_extrausers_chkpwd269442755editdlrm
pam_extrausers_update351360755editdlrm
pam_getenv28900755editdlrm
pam_namespace_helper4670755editdlrm
pam_timestamp_check146560755editdlrm
parted966640755editdlrm
partprobe147200755editdlrm
pdata_tools14305680755editdlrm
perlcalls-bpfcc550755editdlrm
perlflow-bpfcc540755editdlrm
perlstat-bpfcc540755editdlrm
php-fpm7.448033760755editdlrm
phpcalls-bpfcc540755editdlrm
phpdismod72780755editdlrm
phpenmod72780755editdlrm
phpflow-bpfcc530755editdlrm
phpquery63890755editdlrm
phpstat-bpfcc530755editdlrm
pidpersec-bpfcc11110755editdlrm
pidpersec.bt6280755editdlrm
pivot_root147200755editdlrm
plymouthd1500880755editdlrm
poweroff15013040755editdlrm
ppchcalls-bpfcc142240755editdlrm
profile-bpfcc147560755editdlrm
pvchange31567120755editdlrm
pvck31567120755editdlrm
pvcreate31567120755editdlrm
pvdisplay31567120755editdlrm
pvmove31567120755editdlrm
pvremove31567120755editdlrm
pvresize31567120755editdlrm
pvs31567120755editdlrm
pvscan31567120755editdlrm
pwck555920755editdlrm
pwconv472720755editdlrm
pwhistory_helper228480755editdlrm
pwunconv472720755editdlrm
pythoncalls-bpfcc570755editdlrm
pythonflow-bpfcc560755editdlrm
pythongc-bpfcc540755editdlrm
pythonstat-bpfcc560755editdlrm
rdmaucma-bpfcc50730755editdlrm
readahead-bpfcc66940755editdlrm
readprofile229440755editdlrm
reboot15013040755editdlrm
remove-shell11110755editdlrm
reset-trace-bpfcc34980755editdlrm
resize2fs719920755editdlrm
resolvconf1624800755editdlrm
rmmod1743280755editdlrm
rmt560240755editdlrm
rmt-tar560240755editdlrm
rsyslogd7901920755editdlrm
rtacct289920755editdlrm
rtcwake352000755editdlrm
rtmon1193120755editdlrm
rubycalls-bpfcc550755editdlrm
rubyflow-bpfcc540755editdlrm
rubygc-bpfcc520755editdlrm
rubyobjnew-bpfcc560755editdlrm
rubystat-bpfcc540755editdlrm
runlevel15013040755editdlrm
runqlat-bpfcc95260755editdlrm
runqlat.bt7880755editdlrm
runqlen-bpfcc82480755editdlrm
runqlen.bt10370755editdlrm
runqslower-bpfcc92250755editdlrm
runuser556800755editdlrm
service91040755editdlrm
setcap146480755editdlrm
setuids.bt17990755editdlrm
setvesablank147120755editdlrm
setvtrgb147760755editdlrm
sfdisk1089280755editdlrm
sgdisk1827680755editdlrm
shadowconfig22730755editdlrm
shmsnoop-bpfcc79850755editdlrm
shutdown15013040755editdlrm
slabratetop-bpfcc65370755editdlrm
sofdsnoop-bpfcc82550755editdlrm
softirqs-bpfcc57230755editdlrm
solisten-bpfcc61030755editdlrm
sshd9214160755editdlrm
ssllatency.bt21330755editdlrm
sslsniff-bpfcc140130755editdlrm
sslsnoop.bt20410755editdlrm
stackcount-bpfcc166550755editdlrm
start-stop-daemon486320755editdlrm
statsnoop-bpfcc50410755editdlrm
statsnoop.bt12940755editdlrm
sudo_logsrvd2544640755editdlrm
sudo_sendlog1348320755editdlrm
sulogin433920755editdlrm
swapin.bt6000755editdlrm
swaplabel188160755editdlrm
swapoff229120755editdlrm
swapon433920755editdlrm
switch_root229120755editdlrm
syncsnoop-bpfcc13000755editdlrm
syncsnoop.bt8390755editdlrm
syscount-bpfcc87710755editdlrm
syscount.bt8720755editdlrm
sysctl311120755editdlrm
tarcat9360755editdlrm
tc6452000755editdlrm
tclcalls-bpfcc540755editdlrm
tclflow-bpfcc530755editdlrm
tclobjnew-bpfcc550755editdlrm
tclstat-bpfcc530755editdlrm
tcpaccept-bpfcc92200755editdlrm
tcpaccept.bt17560755editdlrm
tcpcong-bpfcc205910755editdlrm
tcpconnect-bpfcc189020755editdlrm
tcpconnect.bt16150755editdlrm
tcpconnlat-bpfcc92850755editdlrm
tcpdrop-bpfcc76160755editdlrm
tcpdrop.bt24690755editdlrm
tcplife-bpfcc169490755editdlrm
tcplife.bt27850755editdlrm
tcpretrans-bpfcc140980755editdlrm
tcpretrans.bt21200755editdlrm
tcprtt-bpfcc89130755editdlrm
tcpstates-bpfcc140640755editdlrm
tcpsubnet-bpfcc78140755editdlrm
tcpsynbl-bpfcc21750755editdlrm
tcpsynbl.bt9620755editdlrm
tcptop-bpfcc129430755editdlrm
tcptracer-bpfcc181300755editdlrm
telinit15013040755editdlrm
thin_check14305680755editdlrm
thin_delta14305680755editdlrm
thin_dump14305680755editdlrm
thin_ls14305680755editdlrm
thin_metadata_size14305680755editdlrm
thin_repair14305680755editdlrm
thin_restore14305680755editdlrm
thin_rmap14305680755editdlrm
thin_trim14305680755editdlrm
threadsnoop-bpfcc18580755editdlrm
threadsnoop.bt7120755editdlrm
tipc926880755editdlrm
tplist-bpfcc41570755editdlrm
trace-bpfcc438920755editdlrm
ttysnoop-bpfcc76940755editdlrm
tune2fs1132160755editdlrm
ucalls119700755editdlrm
uflow81150755editdlrm
ufw49590755editdlrm
ugc78230755editdlrm
umount.udisks2146400755editdlrm
undump.bt7890755editdlrm
unix_chkpwd310402755editdlrm
unix_update351360755editdlrm
uobjnew61810755editdlrm
update-ca-certificates54460755editdlrm
update-catalog93930755editdlrm
update-grub640755editdlrm
update-grub-gfxpayload3010755editdlrm
update-grub2640755editdlrm
update-ieee-data34920755editdlrm
update-info-dir17000755editdlrm
update-initramfs69080755editdlrm
update-locale30570755editdlrm
update-passwd353920755editdlrm
update-pciids17780755editdlrm
update-rc.d181470755editdlrm
update-secureboot-policy76050755editdlrm
update-shells39840755editdlrm
update-xmlcatalog172840755editdlrm
upgrade-from-grub-legacy15960755editdlrm
usb_modeswitch610960755editdlrm
usb_modeswitch_dispatcher274180755editdlrm
useradd1432320755editdlrm
userdel931920755editdlrm
usermod1307120755editdlrm
ustat124120755editdlrm
uthreads41000755editdlrm
uuidd316240755editdlrm
validlocale17730755editdlrm
vcstime146400755editdlrm
vdpa353920755editdlrm
veritysetup449920755editdlrm
vfscount-bpfcc13900755editdlrm
vfscount.bt5150755editdlrm
vfsstat-bpfcc41590755editdlrm
vfsstat.bt7210755editdlrm
vgcfgbackup31567120755editdlrm
vgcfgrestore31567120755editdlrm
vgchange31567120755editdlrm
vgck31567120755editdlrm
vgconvert31567120755editdlrm
vgcreate31567120755editdlrm
vgdisplay31567120755editdlrm
vgexport31567120755editdlrm
vgextend31567120755editdlrm
vgimport31567120755editdlrm
vgimportclone31567120755editdlrm
vgmerge31567120755editdlrm
vgmknodes31567120755editdlrm
vgreduce31567120755editdlrm
vgremove31567120755editdlrm
vgrename31567120755editdlrm
vgs31567120755editdlrm
vgscan31567120755editdlrm
vgsplit31567120755editdlrm
vigr621440755editdlrm
vipw621440755editdlrm
virtiostat-bpfcc89000755editdlrm
visudo2587760755editdlrm
vpddecode149280755editdlrm
wakeuptime-bpfcc82910755editdlrm
wipefs392960755editdlrm
writeback.bt16990755editdlrm
xfsdist-bpfcc47230755editdlrm
xfsdist.bt9720755editdlrm
xfsslower-bpfcc79640755editdlrm
xfs_admin21740755editdlrm
xfs_bmap6950755editdlrm
xfs_copy926080755editdlrm
xfs_db7050880755editdlrm
xfs_estimate145040755editdlrm
xfs_freeze8000755editdlrm
xfs_fsr431920755editdlrm
xfs_growfs391520755editdlrm
xfs_info12940755editdlrm
xfs_io2085360755editdlrm
xfs_logprint801440755editdlrm
xfs_mdrestore350480755editdlrm
xfs_metadump8160755editdlrm
xfs_mkfile10400755editdlrm
xfs_ncheck6850755editdlrm
xfs_quota923280755editdlrm
xfs_repair6587600755editdlrm
xfs_rtcp185840755editdlrm
xfs_scrub1088160755editdlrm
xfs_scrub_all78410755editdlrm
xfs_spaceman433200755editdlrm
xtables-legacy-multi951760755editdlrm
xtables-monitor2244240755editdlrm
xtables-nft-multi2244240755editdlrm
zerofree144880755editdlrm
zfsdist-bpfcc54270755editdlrm
zfsslower-bpfcc86570755editdlrm
zic679840755editdlrm
zramctl558240755editdlrm
Edit: /usr/sbin/tcpconnect-bpfcc (18902B)
#! /usr/bin/python3 # @lint-avoid-python-3-compatibility-imports # # tcpconnect Trace TCP connect()s. # For Linux, uses BCC, eBPF. Embedded C. # # USAGE: tcpconnect [-h] [-c] [-t] [-p PID] [-P PORT [PORT ...]] [-4 | -6] # # All connection attempts are traced, even if they ultimately fail. # # This uses dynamic tracing of kernel functions, and will need to be updated # to match kernel changes. # # Copyright (c) 2015 Brendan Gregg. # Licensed under the Apache License, Version 2.0 (the "License") # # 25-Sep-2015 Brendan Gregg Created this. # 14-Feb-2016 " " Switch to bpf_perf_output. # 09-Jan-2019 Takuma Kume Support filtering by UID # 30-Jul-2019 Xiaozhou Liu Count connects. # 07-Oct-2020 Nabil Schear Correlate connects with DNS responses # 08-Mar-2021 Suresh Kumar Added LPORT option from __future__ import print_function from bcc import BPF from bcc.containers import filter_by_containers from bcc.utils import printb import argparse from socket import inet_ntop, ntohs, AF_INET, AF_INET6 from struct import pack from time import sleep from datetime import datetime # arguments examples = """examples: ./tcpconnect # trace all TCP connect()s ./tcpconnect -t # include timestamps ./tcpconnect -d # include DNS queries associated with connects ./tcpconnect -p 181 # only trace PID 181 ./tcpconnect -P 80 # only trace port 80 ./tcpconnect -P 80,81 # only trace port 80 and 81 ./tcpconnect -4 # only trace IPv4 family ./tcpconnect -6 # only trace IPv6 family ./tcpconnect -U # include UID ./tcpconnect -u 1000 # only trace UID 1000 ./tcpconnect -c # count connects per src ip and dest ip/port ./tcpconnect -L # include LPORT while printing outputs ./tcpconnect --cgroupmap mappath # only trace cgroups in this BPF map ./tcpconnect --mntnsmap mappath # only trace mount namespaces in the map """ parser = argparse.ArgumentParser( description="Trace TCP connects", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=examples) parser.add_argument("-t", "--timestamp", action="store_true", help="include timestamp on output") parser.add_argument("-p", "--pid", help="trace this PID only") parser.add_argument("-P", "--port", help="comma-separated list of destination ports to trace.") group = parser.add_mutually_exclusive_group() group.add_argument("-4", "--ipv4", action="store_true", help="trace IPv4 family only") group.add_argument("-6", "--ipv6", action="store_true", help="trace IPv6 family only") parser.add_argument("-L", "--lport", action="store_true", help="include LPORT on output") parser.add_argument("-U", "--print-uid", action="store_true", help="include UID on output") parser.add_argument("-u", "--uid", help="trace this UID only") parser.add_argument("-c", "--count", action="store_true", help="count connects per src ip and dest ip/port") parser.add_argument("--cgroupmap", help="trace cgroups in this BPF map only") parser.add_argument("--mntnsmap", help="trace mount namespaces in this BPF map only") parser.add_argument("-d", "--dns", action="store_true", help="include likely DNS query associated with each connect") parser.add_argument("--ebpf", action="store_true", help=argparse.SUPPRESS) args = parser.parse_args() debug = 0 # define BPF program bpf_text = """ #include #include #include BPF_HASH(currsock, u32, struct sock *); // separate data structs for ipv4 and ipv6 struct ipv4_data_t { u64 ts_us; u32 pid; u32 uid; u32 saddr; u32 daddr; u64 ip; u16 lport; u16 dport; char task[TASK_COMM_LEN]; }; BPF_PERF_OUTPUT(ipv4_events); struct ipv6_data_t { u64 ts_us; u32 pid; u32 uid; unsigned __int128 saddr; unsigned __int128 daddr; u64 ip; u16 lport; u16 dport; char task[TASK_COMM_LEN]; }; BPF_PERF_OUTPUT(ipv6_events); // separate flow keys per address family struct ipv4_flow_key_t { u32 saddr; u32 daddr; u16 dport; }; BPF_HASH(ipv4_count, struct ipv4_flow_key_t); struct ipv6_flow_key_t { unsigned __int128 saddr; unsigned __int128 daddr; u16 dport; }; BPF_HASH(ipv6_count, struct ipv6_flow_key_t); int trace_connect_entry(struct pt_regs *ctx, struct sock *sk) { if (container_should_be_filtered()) { return 0; } u64 pid_tgid = bpf_get_current_pid_tgid(); u32 pid = pid_tgid >> 32; u32 tid = pid_tgid; FILTER_PID u32 uid = bpf_get_current_uid_gid(); FILTER_UID // stash the sock ptr for lookup on return currsock.update(&tid, &sk); return 0; }; static int trace_connect_return(struct pt_regs *ctx, short ipver) { int ret = PT_REGS_RC(ctx); u64 pid_tgid = bpf_get_current_pid_tgid(); u32 pid = pid_tgid >> 32; u32 tid = pid_tgid; struct sock **skpp; skpp = currsock.lookup(&tid); if (skpp == 0) { return 0; // missed entry } if (ret != 0) { // failed to send SYNC packet, may not have populated // socket __sk_common.{skc_rcv_saddr, ...} currsock.delete(&tid); return 0; } // pull in details struct sock *skp = *skpp; u16 lport = skp->__sk_common.skc_num; u16 dport = skp->__sk_common.skc_dport; FILTER_PORT FILTER_FAMILY if (ipver == 4) { IPV4_CODE } else /* 6 */ { IPV6_CODE } currsock.delete(&tid); return 0; } int trace_connect_v4_return(struct pt_regs *ctx) { return trace_connect_return(ctx, 4); } int trace_connect_v6_return(struct pt_regs *ctx) { return trace_connect_return(ctx, 6); } """ struct_init = {'ipv4': {'count': """ struct ipv4_flow_key_t flow_key = {}; flow_key.saddr = skp->__sk_common.skc_rcv_saddr; flow_key.daddr = skp->__sk_common.skc_daddr; flow_key.dport = ntohs(dport); ipv4_count.increment(flow_key);""", 'trace': """ struct ipv4_data_t data4 = {.pid = pid, .ip = ipver}; data4.uid = bpf_get_current_uid_gid(); data4.ts_us = bpf_ktime_get_ns() / 1000; data4.saddr = skp->__sk_common.skc_rcv_saddr; data4.daddr = skp->__sk_common.skc_daddr; data4.lport = lport; data4.dport = ntohs(dport); bpf_get_current_comm(&data4.task, sizeof(data4.task)); ipv4_events.perf_submit(ctx, &data4, sizeof(data4));""" }, 'ipv6': {'count': """ struct ipv6_flow_key_t flow_key = {}; bpf_probe_read_kernel(&flow_key.saddr, sizeof(flow_key.saddr), skp->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32); bpf_probe_read_kernel(&flow_key.daddr, sizeof(flow_key.daddr), skp->__sk_common.skc_v6_daddr.in6_u.u6_addr32); flow_key.dport = ntohs(dport); ipv6_count.increment(flow_key);""", 'trace': """ struct ipv6_data_t data6 = {.pid = pid, .ip = ipver}; data6.uid = bpf_get_current_uid_gid(); data6.ts_us = bpf_ktime_get_ns() / 1000; bpf_probe_read_kernel(&data6.saddr, sizeof(data6.saddr), skp->__sk_common.skc_v6_rcv_saddr.in6_u.u6_addr32); bpf_probe_read_kernel(&data6.daddr, sizeof(data6.daddr), skp->__sk_common.skc_v6_daddr.in6_u.u6_addr32); data6.lport = lport; data6.dport = ntohs(dport); bpf_get_current_comm(&data6.task, sizeof(data6.task)); ipv6_events.perf_submit(ctx, &data6, sizeof(data6));""" } } # This defines an additional BPF program that instruments udp_recvmsg system # call to locate DNS response packets on UDP port 53. When these packets are # located, the data is copied to user-space where python will parse them with # dnslib. # # uses a percpu array of length 1 to store the dns_data_t off the stack to # allow for a maximum DNS packet length of 512 bytes. dns_bpf_text = """ #include #define MAX_PKT 512 struct dns_data_t { u8 pkt[MAX_PKT]; }; BPF_PERF_OUTPUT(dns_events); // store msghdr pointer captured on syscall entry to parse on syscall return BPF_HASH(tbl_udp_msg_hdr, u64, struct msghdr *); // single element per-cpu array to hold the current event off the stack BPF_PERCPU_ARRAY(dns_data,struct dns_data_t,1); int trace_udp_recvmsg(struct pt_regs *ctx) { __u64 pid_tgid = bpf_get_current_pid_tgid(); struct sock *sk = (struct sock *)PT_REGS_PARM1(ctx); struct inet_sock *is = inet_sk(sk); // only grab port 53 packets, 13568 is ntohs(53) if (is->inet_dport == 13568) { struct msghdr *msghdr = (struct msghdr *)PT_REGS_PARM2(ctx); tbl_udp_msg_hdr.update(&pid_tgid, &msghdr); } return 0; } int trace_udp_ret_recvmsg(struct pt_regs *ctx) { __u64 pid_tgid = bpf_get_current_pid_tgid(); u32 zero = 0; struct msghdr **msgpp = tbl_udp_msg_hdr.lookup(&pid_tgid); if (msgpp == 0) return 0; struct msghdr *msghdr = (struct msghdr *)*msgpp; if (msghdr->msg_iter.TYPE_FIELD != ITER_IOVEC) goto delete_and_return; int copied = (int)PT_REGS_RC(ctx); if (copied < 0) goto delete_and_return; size_t buflen = (size_t)copied; if (buflen > msghdr->msg_iter.iov->iov_len) goto delete_and_return; if (buflen > MAX_PKT) buflen = MAX_PKT; struct dns_data_t *data = dns_data.lookup(&zero); if (!data) // this should never happen, just making the verifier happy return 0; void *iovbase = msghdr->msg_iter.iov->iov_base; bpf_probe_read(data->pkt, buflen, iovbase); dns_events.perf_submit(ctx, data, buflen); delete_and_return: tbl_udp_msg_hdr.delete(&pid_tgid); return 0; } #include int trace_udpv6_recvmsg(struct pt_regs *ctx) { struct sk_buff *skb = (struct sk_buff *)PT_REGS_PARM2(ctx); struct udphdr *hdr = (void*)skb->head + skb->transport_header; struct dns_data_t *event; int zero = 0; void *data; /* hex(53) = 0x0035, htons(0x0035) = 0x3500 */ if (hdr->source != 0x3500) return 0; /* skip UDP header */ data = skb->data + 8; event = dns_data.lookup(&zero); if (!event) return 0; bpf_probe_read(event->pkt, sizeof(event->pkt), data); dns_events.perf_submit(ctx, event, sizeof(*event)); return 0; } """ if args.count and args.dns: print("Error: you may not specify -d/--dns with -c/--count.") exit() # code substitutions if args.count: bpf_text = bpf_text.replace("IPV4_CODE", struct_init['ipv4']['count']) bpf_text = bpf_text.replace("IPV6_CODE", struct_init['ipv6']['count']) else: bpf_text = bpf_text.replace("IPV4_CODE", struct_init['ipv4']['trace']) bpf_text = bpf_text.replace("IPV6_CODE", struct_init['ipv6']['trace']) if args.pid: bpf_text = bpf_text.replace('FILTER_PID', 'if (pid != %s) { return 0; }' % args.pid) if args.port: dports = [int(dport) for dport in args.port.split(',')] dports_if = ' && '.join(['dport != %d' % ntohs(dport) for dport in dports]) bpf_text = bpf_text.replace('FILTER_PORT', 'if (%s) { currsock.delete(&tid); return 0; }' % dports_if) if args.ipv4: bpf_text = bpf_text.replace('FILTER_FAMILY', 'if (ipver != 4) { return 0; }') elif args.ipv6: bpf_text = bpf_text.replace('FILTER_FAMILY', 'if (ipver != 6) { return 0; }') if args.uid: bpf_text = bpf_text.replace('FILTER_UID', 'if (uid != %s) { return 0; }' % args.uid) bpf_text = filter_by_containers(args) + bpf_text bpf_text = bpf_text.replace('FILTER_PID', '') bpf_text = bpf_text.replace('FILTER_PORT', '') bpf_text = bpf_text.replace('FILTER_FAMILY', '') bpf_text = bpf_text.replace('FILTER_UID', '') if args.dns: if BPF.kernel_struct_has_field(b'iov_iter', b'iter_type') == 1: dns_bpf_text = dns_bpf_text.replace('TYPE_FIELD', 'iter_type') else: dns_bpf_text = dns_bpf_text.replace('TYPE_FIELD', 'type') bpf_text += dns_bpf_text if debug or args.ebpf: print(bpf_text) if args.ebpf: exit() # process event def print_ipv4_event(cpu, data, size): event = b["ipv4_events"].event(data) global start_ts if args.timestamp: if start_ts == 0: start_ts = event.ts_us printb(b"%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), nl="") if args.print_uid: printb(b"%-6d" % event.uid, nl="") dest_ip = inet_ntop(AF_INET, pack("I", event.daddr)).encode() if args.lport: printb(b"%-7d %-12.12s %-2d %-16s %-6d %-16s %-6d %s" % (event.pid, event.task, event.ip, inet_ntop(AF_INET, pack("I", event.saddr)).encode(), event.lport, dest_ip, event.dport, print_dns(dest_ip))) else: printb(b"%-7d %-12.12s %-2d %-16s %-16s %-6d %s" % (event.pid, event.task, event.ip, inet_ntop(AF_INET, pack("I", event.saddr)).encode(), dest_ip, event.dport, print_dns(dest_ip))) def print_ipv6_event(cpu, data, size): event = b["ipv6_events"].event(data) global start_ts if args.timestamp: if start_ts == 0: start_ts = event.ts_us printb(b"%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), nl="") if args.print_uid: printb(b"%-6d" % event.uid, nl="") dest_ip = inet_ntop(AF_INET6, event.daddr).encode() if args.lport: printb(b"%-7d %-12.12s %-2d %-16s %-6d %-16s %-6d %s" % (event.pid, event.task, event.ip, inet_ntop(AF_INET6, event.saddr).encode(), event.lport, dest_ip, event.dport, print_dns(dest_ip))) else: printb(b"%-7d %-12.12s %-2d %-16s %-16s %-6d %s" % (event.pid, event.task, event.ip, inet_ntop(AF_INET6, event.saddr).encode(), dest_ip, event.dport, print_dns(dest_ip))) def depict_cnt(counts_tab, l3prot='ipv4'): for k, v in sorted(counts_tab.items(), key=lambda counts: counts[1].value, reverse=True): depict_key = "" if l3prot == 'ipv4': depict_key = "%-25s %-25s %-20s" % \ ((inet_ntop(AF_INET, pack('I', k.saddr))), inet_ntop(AF_INET, pack('I', k.daddr)), k.dport) else: depict_key = "%-25s %-25s %-20s" % \ ((inet_ntop(AF_INET6, k.saddr)), inet_ntop(AF_INET6, k.daddr), k.dport) print("%s %-10d" % (depict_key, v.value)) def print_dns(dest_ip): if not args.dns: return b"" dnsname, timestamp = dns_cache.get(dest_ip, (None, None)) if timestamp is not None: diff = datetime.now() - timestamp diff = float(diff.seconds) * 1000 + float(diff.microseconds) / 1000 else: diff = 0 if dnsname is None: dnsname = b"No DNS Query" if dest_ip == b"127.0.0.1" or dest_ip == b"::1": dnsname = b"localhost" retval = b"%s" % dnsname if diff > DELAY_DNS: retval += b" (%.3fms)" % diff return retval if args.dns: try: import dnslib from cachetools import TTLCache except ImportError: print("Error: The python packages dnslib and cachetools are required " "to use the -d/--dns option.") print("Install this package with:") print("\t$ pip3 install dnslib cachetools") print(" or") print("\t$ sudo apt-get install python3-dnslib python3-cachetools " "(on Ubuntu 18.04+)") exit(1) # 24 hours DEFAULT_TTL = 86400 # Cache Size in entries DNS_CACHE_SIZE = 10240 # delay in ms in which to warn users of long delay between the query # and the connect that used the IP DELAY_DNS = 100 dns_cache = TTLCache(maxsize=DNS_CACHE_SIZE, ttl=DEFAULT_TTL) # process event def save_dns(cpu, data, size): event = b["dns_events"].event(data) payload = event.pkt[:size] # pass the payload to dnslib for parsing dnspkt = dnslib.DNSRecord.parse(payload) # lets only look at responses if dnspkt.header.qr != 1: return # must be some questions in there if dnspkt.header.q != 1: return # make sure there are answers if dnspkt.header.a == 0 and dnspkt.header.aa == 0: return # lop off the trailing . question = ("%s" % dnspkt.q.qname)[:-1].encode('utf-8') for answer in dnspkt.rr: # skip all but A and AAAA records if answer.rtype == 1 or answer.rtype == 28: dns_cache[str(answer.rdata).encode('utf-8')] = (question, datetime.now()) # initialize BPF b = BPF(text=bpf_text) b.attach_kprobe(event="tcp_v4_connect", fn_name="trace_connect_entry") b.attach_kprobe(event="tcp_v6_connect", fn_name="trace_connect_entry") b.attach_kretprobe(event="tcp_v4_connect", fn_name="trace_connect_v4_return") b.attach_kretprobe(event="tcp_v6_connect", fn_name="trace_connect_v6_return") if args.dns: b.attach_kprobe(event="udp_recvmsg", fn_name="trace_udp_recvmsg") b.attach_kretprobe(event="udp_recvmsg", fn_name="trace_udp_ret_recvmsg") b.attach_kprobe(event="udpv6_queue_rcv_one_skb", fn_name="trace_udpv6_recvmsg") print("Tracing connect ... Hit Ctrl-C to end") if args.count: try: while True: sleep(99999999) except KeyboardInterrupt: pass # header print("\n%-25s %-25s %-20s %-10s" % ( "LADDR", "RADDR", "RPORT", "CONNECTS")) depict_cnt(b["ipv4_count"]) depict_cnt(b["ipv6_count"], l3prot='ipv6') # read events else: # header if args.timestamp: print("%-9s" % ("TIME(s)"), end="") if args.print_uid: print("%-6s" % ("UID"), end="") if args.lport: print("%-7s %-12s %-2s %-16s %-6s %-16s %-6s" % ("PID", "COMM", "IP", "SADDR", "LPORT", "DADDR", "DPORT"), end="") else: print("%-7s %-12s %-2s %-16s %-16s %-6s" % ("PID", "COMM", "IP", "SADDR", "DADDR", "DPORT"), end="") if args.dns: print(" QUERY") else: print() start_ts = 0 # read events b["ipv4_events"].open_perf_buffer(print_ipv4_event) b["ipv6_events"].open_perf_buffer(print_ipv6_event) if args.dns: b["dns_events"].open_perf_buffer(save_dns) while True: try: b.perf_buffer_poll() except KeyboardInterrupt: exit()