.
script, , strace:
#!/bin/bash
BACKSPACE='\10\33[K'
BACKSPACE_EMPTY='\7'
BACKSLASH='\\'
QUOTE="\'"
DOUBLE_QUOUTE='\"'
LARROW='\10'
RARROW='\33[C'
BACKSPACE_='\\33\[1P'
BADBIN='\\33\]'
while read -r line
do
NOBINline=$(echo "${line}" | strings)
CURRENT_PWD_OF_PID=$(readlink -f /proc/${1}/cwd)
USER_OF_PID=$(cat /proc/${1}/environ | strings | tr '.' ' ' | grep USER | awk -F= '{print $2}')
HOSTNAME_OF_PID=`hostname -a`
STR_TO_REMOVE=$(printf "${USER_OF_PID}""@""${HOSTNAME_OF_PID}"":""${CURRENT_PWD_OF_PID}")
parsed_line=$(echo "${NOBINline}" | perl -nale 'print $1 if ~/\"(.*)\"/gi')
if [ "${parsed_line}" == "\n" ]
then
parsed_line="{{ENTER}}"
fi
output_line=''
inchar_line=''
postinchar_line=''
inchar_line=$(printf "${parsed_line}")
if [ "${inchar_line}" == "{{ENTER}}" ]
then
echo ""
else
output_line=$(printf "${output_line}""${inchar_line}")
fi
if [ "${output_line}" != "${CURRENT_PWD_OF_PID}" -a "${output_line}" != "${STR_TO_REMOVE}" -a `echo "${NOBINline}" | grep -c "${BADBIN}"` -eq 0 ]
then
printf "${output_line}"
fi
done < <(sudo strace -e trace=write -s1000 -p $1 2>/dev/stdout)
:
./script.sh <PID_of_mointored_console>
script ( , ):
#!/bin/bash
while [ 1 ]
do
for PIDs in `ps awwux | grep [p]ts | grep bash | grep -v lets | grep -v log_start | grep -v grep | awk '{print $2}'`
do
PTS=$(ps awwux | grep "${PIDs}" | grep -v grep | awk '{print $7}')
if [ -f /tmp/bash_log.${PIDs} ]
then
sleep 1
else
touch /tmp/bash_log.${PIDs}
/bin/bash /root/lets.sh $PIDs >> /tmp/bash_log.${PIDs} &
fi
done
for IFEMPTY in `find /tmp/ -type f -name 'bash_log*' -mmin +600`
do
if [ `cat "${IFEMPTY}" | grep -v "\'" | wc -c` -lt 2 ]
then
rm -rf "${IFEMPTY}"
else
sleep 1
fi
done
done
, script.
firstscript.sh <PID>
/tmp/bash_log.<PID>
.
:
./monitor.sh &
[sahaquiel@sahaquiel-PC ~]$ echo $$
916
[sahaquiel@sahaquiel-PC ~]$ HELO, IM A NEW STRING
bash: HELO,: command not found
[sahaquiel@sahaquiel-PC ~]$ tail -n3 /tmp/bash_log.916
916
''[sahaquiel@sahaquiel-PC ~]$ HELO, IM A NEW STRING
'''[sahaquiel@sahaquiel-PC ~]$ tail -n3 /tmp/bash_log.916
NB. , .
/tmp/bash_log
. , Ctrl+R
, Ctrl+C
, :
'''[sahaquiel@sahaquiel-PC ~]$ I WILL TYPE BACKSLASH THREE TIMES IN THE END OF THIS STRING 123[BACKSPACE] [Backspace found. Rewritten string]: βββββ>
'''[sahaquiel@sahaquiel-PC ~]$ I WILL TYPE BACKSLASH THREE TIMES IN THE END OF THIS STRING 12[BACKSPACE] [Backspace found. Rewritten string]: βββββ>
'''[sahaquiel@sahaquiel-PC ~]$ I WILL TYPE BACKSLASH THREE TIMES IN THE END OF THIS STRING 1[BACKSPACE] [Backspace found. Rewritten string]: βββββ>
'''[sahaquiel@sahaquiel-PC ~]$ I WILL TYPE BACKSLASH THREE TIMES IN THE END OF THIS STRING
'''[sahaquiel@sahaquiel-PC ~]$ NOW I I[BACKSPACE] [Backspace found. Rewritten string]: βββββ>
'''[sahaquiel@sahaquiel-PC ~]$ NOW I WILL PRESS \"LEFT ARROW\" THREE TIMES[LARROW] [Left arrow found.]: βββββ>
'''[sahaquiel@sahaquiel-PC ~]$ NOW I WILL PRESS \"LEFT ARROW\" THREE TIME[LARROW]S[LARROW] [Left arrow found.]: βββββ>
'''[sahaquiel@sahaquiel-PC ~]$ NOW I WILL PRESS \"LEFT ARROW\" THREE TIM[LARROW]ES[LARROW] [Left arrow found.]: βββββ>
'''[sahaquiel@sahaquiel-PC ~]$ NOW I WILL PRESS \"LEFT ARROW\" THREE TI[LARROW]MES
.
, , .
P.S. - , Github ( )