@@ -1327,12 +1327,14 @@ _warn_upx_exe() {
13271327
13281328memdump () {
13291329 local pid=" ${1:? } "
1330- local x exe=$( readlink -f /proc/${pid} /exe 2> /dev/null)
1330+ local out x exe=$( readlink -f /proc/${pid} /exe 2> /dev/null)
13311331 exe=" ${exe##*/ } "
13321332
1333- cat " /proc/${pid} /maps" | cut -f1 -d" " | while read -r x; do
1333+ cat " /proc/${pid} /maps" > ${pid} _${exe} _maps.txt
1334+ grep -E " ${2:- .} " " /proc/${pid} /maps" | cut -f1 -d" " | while read -r x; do
13341335 echo -e " ${pid} \t ${exe} \t 0x${x%% -* } -0x${x##* -} "
1335- gdb --batch --pid " $pid " " /proc/${pid} /exe" -ex " dump memory ${pid} _${exe} _${x%% -* } -${x##* -} 0x${x%% -* } 0x${x##* -} " & > /dev/null
1336+ out=" ${pid} _${exe} _${x%% -* } -${x##* -} "
1337+ gdb --batch --pid " $pid " " /proc/${pid} /exe" -ex " dump memory ${out} 0x${x%% -* } 0x${x##* -} " & > /dev/null
13361338 done
13371339}
13381340
@@ -1350,13 +1352,21 @@ _hs_gdb_proc_match() {
13501352 done
13511353}
13521354
1355+ # Send stdin to abstract unix domain socket and print response to stdout
1356+ _audsock () {
1357+ perl -e ' use IO::Socket::UNIX;$n=shift||"";$n=~s/^@//;$p="\0".$n;$s=IO::Socket::UNIX->new(Peer=>$p,Type=>SOCK_STREAM)||die$!;binmode(STDIN);binmode(STDOUT);binmode($s);$fd=fileno($s);$w="";vec($w,$fd,1)=1;select(undef,$w,undef,undef);while(1){my$buf;my$r=sysread(STDIN,$buf,4096);die"read STDIN:$!"unless defined$r;last if$r==0;my$o=0;while($o<$r){my$w=syswrite($s,$buf,$r-$o,$o);die"write:$!"unless defined$w;$o+=$w}}shutdown($s,1);while(1){my$buf;my$r=sysread($s,$buf,4096);die"read sock:$!"unless defined$r;last if$r==0;print$buf}close$s;exit;' @" ${1:? } "
1358+ }
1359+ # Determine the Ebury abstract unix domain socket
1360+ _ebsock () { [ -z " $_HS_EBSOCK " ] && _HS_EBSOCK=$( grep -Eom1 ' event-[a-zA-Z0-9]{10,}' /proc/net/unix) ; echo " ${_HS_EBSOCK} " ; }
1361+
13531362_detect_ebury () {
1354- local st bin=$( readlink -f $( ldd -v $( command -v sshd 2> /dev/null) 2> /dev/null | grep -F ' keyutils' | awk ' {print $3}' | head -n1) 2> /dev/null)
1363+ local st bin=$( readlink -f $( ldd -v $( PATH= " ${PATH} :/usr/sbin " command -v sshd 2> /dev/null) 2> /dev/null | grep -F ' keyutils' | awk ' {print $3}' | head -n1) 2> /dev/null)
13551364
13561365 [ -n " $bin " ] && [ -f " $bin " ] && {
13571366 st=$( stat " ${bin} " )
13581367
13591368 rv=$( ls -l " ${bin} " )
1369+ rvdate=$( stat " ${bin} " | grep Change | cut -f2-3 -d' ' )
13601370 { [[ " $st " == * " -rwsr" * ]] || [[ " $st " == * " -rwSr" * ]] || [[ " $st " == * " -r-sr" * ]] || [[ " $st " == * " -r-Sr" * ]]; } && return 0 # # YES
13611371
13621372 v=$( stat --format=' %s' " ${bin} " )
@@ -1374,15 +1384,33 @@ _detect_ebury() {
13741384 return 255 # # NOT found.
13751385}
13761386
1387+ _ebdump () {
1388+ local s
1389+
1390+ echo -e " ${CN}${CDY} Dumping Ebury log via @$( _ebsock) :${CF} "
1391+ while : ; do
1392+ s=" $( printf " \2\0\0\0\0\0\0\0\0\0\0\0\0" | _audsock " $( _ebsock) " | strings) "
1393+ [ -z " $s " ] && break
1394+ echo " $s "
1395+ done | column -t
1396+ echo -en " ${CN} "
1397+ }
1398+
13771399# https://www.travismathison.com/posts/Decoding-Ebury-Malware-SSH-Commands/
13781400# https://web-assets.esetstatic.com/wls/en/papers/white-papers/ebury-is-alive-but-unseen.pdf
13791401# Pesty criminals mass owning. Fuck'm
13801402_warn_ebury () {
1381- local rv
1403+ local rv pid rvdate
13821404 _detect_ebury || return
13831405
1384- echo -e " ${CR} Ebury backdoor detected.${CF} "
1406+ echo -e " ${CR} Ebury backdoor detected [Installation date: ${rvdate :- unknown} ] .${CF} "
13851407 echo " $rv " $' \033 [0m'
1408+
1409+ pid=$( printf ' \4\5\0\0\0\0\0\0' | _audsock " $( _ebsock) " | perl -e ' read STDIN,$b,8;print unpack("x4V",$b)' )
1410+ [ -z " $pid " ] && return
1411+ echo -e " ${CR} Ebury Master hiding as process:${CF} "
1412+ ps -ouser -opid -oppid -ocmd -ocommand -p " ${pid} " ;
1413+ _ebdump
13861414}
13871415
13881416# Warn of script kiddies
0 commit comments