From aa8fc8e17a0bd61d6fb56a9d02acbee19b00c2ce Mon Sep 17 00:00:00 2001 From: "john jayson b. de leon" Date: Thu, 30 Sep 2021 19:08:32 +0800 Subject: [PATCH 1/3] finish adding git in the project --- HexToTxtFile.py | 22 +-- README.md | 42 ++--- img-inject.py | 408 ++++++++++++++++++++++++------------------------ 3 files changed, 236 insertions(+), 236 deletions(-) diff --git a/HexToTxtFile.py b/HexToTxtFile.py index 7fe3197..9cba5bc 100644 --- a/HexToTxtFile.py +++ b/HexToTxtFile.py @@ -1,11 +1,11 @@ - - -def extractFileToHexFormat(file,text): - with open(f'{file}','rb') as file: - with open(f'{text}','w') as text: - text.write(str(file.read())) - -file = input('[executable filename]:') -text = input('[text filename]: ') -extractFileToHexFormat(file,text) - + + +def extractFileToHexFormat(file,text): + with open(f'{file}','rb') as file: + with open(f'{text}','w') as text: + text.write(str(file.read())) + +file = input('[executable filename]:') +text = input('[text filename]: ') +extractFileToHexFormat(file,text) + diff --git a/README.md b/README.md index df6b60c..140f25c 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ -# Hidden Code Image Injector
-## tools that help inject,extract,and remove executable code
-## in a image using python
- -## How to use it
-```python3 img-injector [option] ``` - -> inject the code in the image -``` python3 img-injector -i,--inject ``` - -> extract the code in the image -``` python3 img-injector -e,--extract ``` - -> remove the code in the image -``` python3 img-injector -r,--remove ``` - -> to know if the code exit in the image -``` python3 img-injector -x,--isExist ``` - -> break silent input and be verbose -``` python3 img-injector -v,--verbose ``` +# Hidden Code Image Injector
+## tools that help inject,extract,and remove executable code
+## in a image using python
+ +## How to use it
+```python3 img-injector [option] ``` + +> inject the code in the image +``` python3 img-injector -i,--inject ``` + +> extract the code in the image +``` python3 img-injector -e,--extract ``` + +> remove the code in the image +``` python3 img-injector -r,--remove ``` + +> to know if the code exit in the image +``` python3 img-injector -x,--isExist ``` + +> break silent input and be verbose +``` python3 img-injector -v,--verbose ``` diff --git a/img-inject.py b/img-inject.py index e5892ae..a2d9624 100644 --- a/img-inject.py +++ b/img-inject.py @@ -1,204 +1,204 @@ -""" - Author: John Jayson B. De Leon - Github: savjaylade84 - Email:savjaylade84@gmail.com - - tools for injecting executable code in the image - using python. - - usage: img-inject [option] -""" - -import argparse - -parser = argparse.ArgumentParser( -description='''python tools for injecting,extracting,and removing executable code in the image.''', -formatter_class=argparse.RawDescriptionHelpFormatter,epilog=''' -Author: John Jayson B. De Leon -Email: savjaylade84@gmail.com -Github: savjaylade84 - ''',prog='python3 img-inject.py',usage='%(prog)s [options] ') - -parser.add_argument("image",help="image name") -parser.add_argument("executable",help="executable code") - -parser.add_argument('-r','--remove' - ,help='remove code from the image' - ,action='store_true' - ,default=False) - -parser.add_argument('-e','--extract' - ,help='extract code from the image' - ,action='store_true' - ,default=False) - -parser.add_argument('-x','--isExist' - ,help='read the image and show if there\'s existing code' - ,action='store_true' - ,default=False) - -parser.add_argument('-i','--inject' - ,help='inject the executable code' - ,action='store_true' - ,default=False) - -parser.add_argument('-v','--verbose' - ,help='give more update in the process (default is in silent)' - ,action='store_true' - ,default=False) - -args = parser.parse_args() - - -def prompt(message,verbose): - if verbose: - print(message) - pass - -def isImageExtension(string): - if '.png' in string or '.jpeg' in string or'jpg' in string: - return True - return False - -def imageHexEnd(content): - #check if the image is from painter or photo editing software - #why i put two different finding end here because the - #hex ending of a painter is different from a common picture - #that's why i use two different approach. - if(content.count(bytes.fromhex(b'\x00IEND\xaeB`\x82'.hex())) > 0): - offset = content.index(bytes.fromhex(b'\x00IEND\xaeB`\x82'.hex())) - return offset + 9 - - if(content.count(bytes.fromhex('FFD9')) > 0): - offset = content.index(bytes.fromhex('FFD9')) - return offset + 2 - return 0 - -""" - check if the image hex end has next hex code -""" -def imageHexEnd_next(content,index): - try: - temp = content[index] - return True - except: - return False - -def inject(image,executable): - prompt('-- checking the files --',args.verbose) - if isImageExtension(image): - prompt('[/] done checking the files.',args.verbose) - try: - prompt('-- opening the files --',args.verbose) - with open(f'{image}','ab') as fi, open(f'{executable}','rb') as fe: - prompt('[/] done file existed.',args.verbose) - prompt('-- attempting to inject --',args.verbose) - fi.write(fe.read()) - prompt('[/] done injecting.',args.verbose) - prompt('[/] injecting is complete.',True) - prompt('[/]process is done--',args.verbose) - prompt('-- program exiting --',args.verbose) - except FileNotFoundError: - prompt('Error: failed to inject code in a image',args.verbose) - else: - prompt('Error: Image is not in a proper file format',args.verbose) - -def extract(image,executable): - - prompt('-- checking the files --',args.verbose) - if isImageExtension(image): - prompt('[/] finished.',args.verbose) - - try: - prompt('-- opening the files --',args.verbose) - with open(f'{image}','rb') as file: - - prompt('[/] Existed.',args.verbose) - prompt('-- reading and locating the executable code in the image --',args.verbose) - content = file.read() - - file.seek(imageHexEnd(content)) - - prompt('[/] done reading and locating.',args.verbose) - prompt('-- creating or opening a file for the executable code --',args.verbose) - with open(f'{executable}','wb') as exe: - prompt('[/] done creating or opening a file.',args.verbose) - prompt('-- writing the executable code in the file --',args.verbose) - exe.write(file.read()) - prompt('[/] done writing the file.',args.verbose) - prompt('[/] extracting is complete.',True) - prompt('[/]process is done--',args.verbose) - prompt('-- program exiting --',args.verbose) - - except FileNotFoundError: - prompt('Error: failed to extract code in a image',True) - else: - prompt('Error: Image is not in a proper file format',True) - - -def remove(image): - prompt('-- checking the files --',args.verbose) - if isImageExtension(image): - prompt('[/] finished.',args.verbose) - try: - prompt('-- opening the files --',args.verbose) - with open(f'{image}','rb') as fread: - prompt('[/] Existed.',args.verbose) - prompt('-- reading and locating the executable code in the image --',args.verbose) - content = fread.read() - if(imageHexEnd(content) == None): - prompt('[/] done scanning no injected executable code.',args.verbose) - prompt('[*] aborting removing process.',args.verbose) - else: - prompt('-- initiate removing process --',args.verbose) - prompt('[*]seperating image hex to executable hex.',args.verbose) - newContent = content[0:imageHexEnd(content)] - with open(f'{image}','wb') as fwrite: - fwrite.write(newContent.strip()) - prompt('[/] done seperating.',args.verbose) - prompt('[/] removing is complete.',True) - prompt('[/]process is done--',args.verbose) - prompt('-- program exiting --',args.verbose) - - except FileNotFoundError: - prompt('Error: failed to extract code in a image',True) - else: - prompt('Error: Image is not in a proper file format',True) - -def isExist(image): - prompt('-- checking the files --',args.verbose) - if isImageExtension(image): - prompt('[/] finished.',args.verbose) - try: - prompt('-- opening the files --',args.verbose) - with open(f'{image}','rb') as file: - prompt('[/] Existed.',args.verbose) - prompt('-- scanning the executable code in the image --',args.verbose) - content = file.read() - if not imageHexEnd_next(content,imageHexEnd(content)): - prompt('[/] done scanning no injected executable code.',True) - else: - prompt('[/] done scanning executable code is exist in the image.',True) - prompt('[/]process is done--',args.verbose) - prompt('-- program exiting --',args.verbose) - except FileNotFoundError: - prompt('Error: failed to extract code in a image',True) - else: - prompt('Error: Image is not in a proper file format',True) - -if args.inject: - prompt('## injecting process ##',args.verbose) - inject(args.image,args.executable) - -if args.extract: - prompt('## extracting process ##',args.verbose) - extract(args.image,args.executable) - -if args.remove: - prompt('## removing ##',args.verbose) - remove(args.image) - -if args.isExist: - prompt('## checking ##',args.verbose) - isExist(args.image) - +""" + Author: John Jayson B. De Leon + Github: savjaylade84 + Email:savjaylade84@gmail.com + + tools for injecting executable code in the image + using python. + + usage: img-inject [option] +""" + +import argparse + +parser = argparse.ArgumentParser( +description='''python tools for injecting,extracting,and removing executable code in the image.''', +formatter_class=argparse.RawDescriptionHelpFormatter,epilog=''' +Author: John Jayson B. De Leon +Email: savjaylade84@gmail.com +Github: savjaylade84 + ''',prog='python3 img-inject.py',usage='%(prog)s [options] ') + +parser.add_argument("image",help="image name") +parser.add_argument("executable",help="executable code") + +parser.add_argument('-r','--remove' + ,help='remove code from the image' + ,action='store_true' + ,default=False) + +parser.add_argument('-e','--extract' + ,help='extract code from the image' + ,action='store_true' + ,default=False) + +parser.add_argument('-x','--isExist' + ,help='read the image and show if there\'s existing code' + ,action='store_true' + ,default=False) + +parser.add_argument('-i','--inject' + ,help='inject the executable code' + ,action='store_true' + ,default=False) + +parser.add_argument('-v','--verbose' + ,help='give more update in the process (default is in silent)' + ,action='store_true' + ,default=False) + +args = parser.parse_args() + + +def prompt(message,verbose): + if verbose: + print(message) + pass + +def isImageExtension(string): + if '.png' in string or '.jpeg' in string or'jpg' in string: + return True + return False + +def imageHexEnd(content): + #check if the image is from painter or photo editing software + #why i put two different finding end here because the + #hex ending of a painter is different from a common picture + #that's why i use two different approach. + if(content.count(bytes.fromhex(b'\x00IEND\xaeB`\x82'.hex())) > 0): + offset = content.index(bytes.fromhex(b'\x00IEND\xaeB`\x82'.hex())) + return offset + 9 + + if(content.count(bytes.fromhex('FFD9')) > 0): + offset = content.index(bytes.fromhex('FFD9')) + return offset + 2 + return 0 + +""" + check if the image hex end has next hex code +""" +def imageHexEnd_next(content,index): + try: + temp = content[index] + return True + except: + return False + +def inject(image,executable): + prompt('-- checking the files --',args.verbose) + if isImageExtension(image): + prompt('[/] done checking the files.',args.verbose) + try: + prompt('-- opening the files --',args.verbose) + with open(f'{image}','ab') as fi, open(f'{executable}','rb') as fe: + prompt('[/] done file existed.',args.verbose) + prompt('-- attempting to inject --',args.verbose) + fi.write(fe.read()) + prompt('[/] done injecting.',args.verbose) + prompt('[/] injecting is complete.',True) + prompt('[/]process is done--',args.verbose) + prompt('-- program exiting --',args.verbose) + except FileNotFoundError: + prompt('Error: failed to inject code in a image',args.verbose) + else: + prompt('Error: Image is not in a proper file format',args.verbose) + +def extract(image,executable): + + prompt('-- checking the files --',args.verbose) + if isImageExtension(image): + prompt('[/] finished.',args.verbose) + + try: + prompt('-- opening the files --',args.verbose) + with open(f'{image}','rb') as file: + + prompt('[/] Existed.',args.verbose) + prompt('-- reading and locating the executable code in the image --',args.verbose) + content = file.read() + + file.seek(imageHexEnd(content)) + + prompt('[/] done reading and locating.',args.verbose) + prompt('-- creating or opening a file for the executable code --',args.verbose) + with open(f'{executable}','wb') as exe: + prompt('[/] done creating or opening a file.',args.verbose) + prompt('-- writing the executable code in the file --',args.verbose) + exe.write(file.read()) + prompt('[/] done writing the file.',args.verbose) + prompt('[/] extracting is complete.',True) + prompt('[/]process is done--',args.verbose) + prompt('-- program exiting --',args.verbose) + + except FileNotFoundError: + prompt('Error: failed to extract code in a image',True) + else: + prompt('Error: Image is not in a proper file format',True) + + +def remove(image): + prompt('-- checking the files --',args.verbose) + if isImageExtension(image): + prompt('[/] finished.',args.verbose) + try: + prompt('-- opening the files --',args.verbose) + with open(f'{image}','rb') as fread: + prompt('[/] Existed.',args.verbose) + prompt('-- reading and locating the executable code in the image --',args.verbose) + content = fread.read() + if(imageHexEnd(content) == None): + prompt('[/] done scanning no injected executable code.',args.verbose) + prompt('[*] aborting removing process.',args.verbose) + else: + prompt('-- initiate removing process --',args.verbose) + prompt('[*]seperating image hex to executable hex.',args.verbose) + newContent = content[0:imageHexEnd(content)] + with open(f'{image}','wb') as fwrite: + fwrite.write(newContent.strip()) + prompt('[/] done seperating.',args.verbose) + prompt('[/] removing is complete.',True) + prompt('[/]process is done--',args.verbose) + prompt('-- program exiting --',args.verbose) + + except FileNotFoundError: + prompt('Error: failed to extract code in a image',True) + else: + prompt('Error: Image is not in a proper file format',True) + +def isExist(image): + prompt('-- checking the files --',args.verbose) + if isImageExtension(image): + prompt('[/] finished.',args.verbose) + try: + prompt('-- opening the files --',args.verbose) + with open(f'{image}','rb') as file: + prompt('[/] Existed.',args.verbose) + prompt('-- scanning the executable code in the image --',args.verbose) + content = file.read() + if not imageHexEnd_next(content,imageHexEnd(content)): + prompt('[/] done scanning no injected executable code.',True) + else: + prompt('[/] done scanning executable code is exist in the image.',True) + prompt('[/]process is done--',args.verbose) + prompt('-- program exiting --',args.verbose) + except FileNotFoundError: + prompt('Error: failed to extract code in a image',True) + else: + prompt('Error: Image is not in a proper file format',True) + +if args.inject: + prompt('## injecting process ##',args.verbose) + inject(args.image,args.executable) + +if args.extract: + prompt('## extracting process ##',args.verbose) + extract(args.image,args.executable) + +if args.remove: + prompt('## removing ##',args.verbose) + remove(args.image) + +if args.isExist: + prompt('## checking ##',args.verbose) + isExist(args.image) + From 73ff3ab1bd9af2e1fc36b533385c64c17fbe634d Mon Sep 17 00:00:00 2001 From: "john jayson b. de leon" Date: Thu, 30 Sep 2021 19:18:01 +0800 Subject: [PATCH 2/3] fix readme file --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 140f25c..f216e51 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # Hidden Code Image Injector
-## tools that help inject,extract,and remove executable code
-## in a image using python
- -## How to use it
+## tools that help inject,extract,and remove executable code
in a image using python
How to use it
```python3 img-injector [option] ``` > inject the code in the image From 242e8bf1542116297586f9a576a77613b3495bda Mon Sep 17 00:00:00 2001 From: "john jayson b. de leon" Date: Thu, 30 Sep 2021 19:19:09 +0800 Subject: [PATCH 3/3] fix readme file --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f216e51..0da7f82 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Hidden Code Image Injector
-## tools that help inject,extract,and remove executable code
in a image using python
How to use it
+## tools that help inject,extract,and remove executable code
in a image using python
+## How to use it
```python3 img-injector [option] ``` > inject the code in the image