Skip to content

This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.

Add files via upload

Abdul Wahab Junaid8f1c185d2daa
diff --git a/Python Tools/Web Penetration/flask_debug.py b/Python Tools/Web Penetration/flask_debug.py
new file mode 100644
index 0000000..4029bef
--- /dev/null
+++ b/Python Tools/Web Penetration/flask_debug.py
@@ -0,0 +1,16 @@
+from flask import Flask
+
+app = Flask(__name__)
+
+class MyException(Exception):
+ status_code = 400
+
+ def __init__(self, message, status_code):
+ Exception.__init__(self)
+
[email protected]('/showException')
+def main():
+ raise MyException('MyException', status_code=500)
+
+if __name__ == ' __main__ ':
+ app.run(debug = True) #insecure
diff --git a/Python Tools/Web Penetration/flask_redirect_insecure.py b/Python Tools/Web Penetration/flask_redirect_insecure.py
new file mode 100644
index 0000000..1f9e82a
--- /dev/null
+++ b/Python Tools/Web Penetration/flask_redirect_insecure.py
@@ -0,0 +1,17 @@
+from flask import Flask, redirect, Response
+app = Flask(__name__)
+
[email protected]('/redirect')
+def redirect_url():
+ return redirect("http://www.domain.com/", code=302) #insecure
+
[email protected]('/url/<url>')
+def change_location(url):
+ response = Response()
+ headers = response.headers
+ headers["location"] = url # insecure
+ return response.headers["location"]
+
+
+if __name__ == ' __main__ ':
+ app.run(debug = True)
diff --git a/Python Tools/Web Penetration/flask_redirect_secure.py b/Python Tools/Web Penetration/flask_redirect_secure.py
new file mode 100644
index 0000000..a59b365
--- /dev/null
+++ b/Python Tools/Web Penetration/flask_redirect_secure.py
@@ -0,0 +1,19 @@
+from flask import Flask, redirect, Response
+app = Flask(__name__)
+
+valid_locations = ['www.packtpub.com', 'valid_url']
+
[email protected]('/redirect/<url>')
+def redirect_url(url):
+ sanitizedLocation = getSanitizedLocation(url) #secure
+ print(sanitizedLocation)
+ return redirect("http://"+sanitizedLocation,code=302)
+
+def getSanitizedLocation(location):
+ if (location in valid_locations):
+ return location
+ else:
+ return "check url"
+
+if __name__ == ' __main__ ':
+ app.run(debug = True)
diff --git a/Python Tools/Web Penetration/flask_template_insecure.py b/Python Tools/Web Penetration/flask_template_insecure.py
new file mode 100644
index 0000000..108af74
--- /dev/null
+++ b/Python Tools/Web Penetration/flask_template_insecure.py
@@ -0,0 +1,12 @@
+from flask import Flask , request , make_response
+app = Flask(__name__)
+
[email protected] ('/info',methods =['GET'])
+def getInfo():
+ parameter = request.args.get('parameter','')#insecure
+ html = open('templates/template.html').read()
+ response = make_response(html.replace('{{ data }}',parameter))
+ return response
+
+if __name__ == ' __main__ ':
+ app.run(debug = True)
diff --git a/Python Tools/Web Penetration/flask_template_secure.py b/Python Tools/Web Penetration/flask_template_secure.py
new file mode 100644
index 0000000..0690885
--- /dev/null
+++ b/Python Tools/Web Penetration/flask_template_secure.py
@@ -0,0 +1,14 @@
+from flask import Flask , request , make_response
+from flask import escape
+
+app = Flask(__name__)
+
[email protected] ('/info',methods =['GET'])
+def getInfo():
+ parameter = escape(request.args.get('parameter',''))#secure
+ html = open('templates/template.html').read()
+ response = make_response(html.replace('{{ data }}',parameter))
+ return response
+
+if __name__ == ' __main__ ':
+ app.run(debug = True)
diff --git a/Python Tools/Web Penetration/load_os_module.py b/Python Tools/Web Penetration/load_os_module.py
new file mode 100644
index 0000000..a32762d
--- /dev/null
+++ b/Python Tools/Web Penetration/load_os_module.py
@@ -0,0 +1,7 @@
+import os
+
+try:
+ eval("__import__('os').system('clear')", {})
+ print("Module OS loaded by eval")
+except Exception as exception:
+ print(repr(exception))
diff --git a/Python Tools/Web Penetration/pickle_safe_chroot.py b/Python Tools/Web Penetration/pickle_safe_chroot.py
new file mode 100644
index 0000000..79bdcea
--- /dev/null
+++ b/Python Tools/Web Penetration/pickle_safe_chroot.py
@@ -0,0 +1,29 @@
+import os
+import pickle
+from contextlib import contextmanager
+
+class ShellSystemChroot(object):
+
+ def __reduce__(self):
+ # this will list contents of root / folder
+ return (os.system, ('ls /',))
+
+@contextmanager
+def system_chroot():
+ """ A simple chroot """
+ os.chroot('/')
+ yield
+
+def serialize():
+ with system_chroot():
+ shellcode = pickle.dumps(ShellSystemChroot())
+ return shellcode
+
+def deserialize(exploit_code):
+ with system_chroot():
+ pickle.loads(exploit_code)
+
+if __name__ == '__main__':
+ shellcode = serialize()
+ print('Obtaining files...')
+ deserialize(shellcode)
diff --git a/Python Tools/Web Penetration/pickle_vulnerable_reduce.py b/Python Tools/Web Penetration/pickle_vulnerable_reduce.py
new file mode 100644
index 0000000..0a64335
--- /dev/null
+++ b/Python Tools/Web Penetration/pickle_vulnerable_reduce.py
@@ -0,0 +1,19 @@
+import os
+import pickle
+
+class Vulnerable(object):
+ def __reduce__(self):
+ # Note: this will only list files in your directory.
+ return (os.system, ('ls',))
+
+def serialize_exploit():
+ shellcode = pickle.dumps(Vulnerable())
+ return shellcode
+
+def insecure_deserialize(exploit_code):
+ pickle.loads(exploit_code)
+
+if __name__ == '__main__':
+ shellcode = serialize_exploit()
+ print('Obtaining files...')
+ insecure_deserialize(shellcode)
diff --git a/Python Tools/Web Penetration/pickle_yaml_insecure.py b/Python Tools/Web Penetration/pickle_yaml_insecure.py
new file mode 100644
index 0000000..257b44f
--- /dev/null
+++ b/Python Tools/Web Penetration/pickle_yaml_insecure.py
@@ -0,0 +1,10 @@
+import os
+import pickle
+import yaml
+user_input = input()
+
+with open(user_input,'rb') as file:
+ contents = pickle.load(file) # insecure
+
+with open(user_input, 'rb') as file:
+ contents = yaml.load(file) # insecure
diff --git a/Python Tools/Web Penetration/subprocess_insecure.py b/Python Tools/Web Penetration/subprocess_insecure.py
new file mode 100644
index 0000000..b4f2ff5
--- /dev/null
+++ b/Python Tools/Web Penetration/subprocess_insecure.py
@@ -0,0 +1,7 @@
+import subprocess
+
+data = input()
+command = ' echo ' + data + ' >> ' + ' file.txt '
+subprocess.call(command, shell = True) #insecure
+with open('file.txt','r') as file:
+ data = file.read()
diff --git a/Python Tools/Web Penetration/subprocess_ping_server_insecure.py b/Python Tools/Web Penetration/subprocess_ping_server_insecure.py
new file mode 100644
index 0000000..2aba76c
--- /dev/null
+++ b/Python Tools/Web Penetration/subprocess_ping_server_insecure.py
@@ -0,0 +1,8 @@
+import subprocess
+
+#the problem with this method is that the shell can
+#process other commands that are provided by the user after the ping command terminates.
+def ping_insecure(myserver):
+ return subprocess.Popen('ping -c 1 %s' % myserver, shell=True)
+
+print(ping_insecure('8.8.8.8 & touch file'))
diff --git a/Python Tools/Web Penetration/subprocess_ping_server_secure.py b/Python Tools/Web Penetration/subprocess_ping_server_secure.py
new file mode 100644
index 0000000..3714ca4
--- /dev/null
+++ b/Python Tools/Web Penetration/subprocess_ping_server_secure.py
@@ -0,0 +1,12 @@
+import subprocess
+
+
+#Rather than passing a string to subprocess, our function passes a list of strings.
+#The ping program gets each argument separately,
+#so the shell does not process other commands that are provided by the user after the ping #command terminates.
+
+def ping_secure(myserver):
+ command_arguments = ['ping','-c','1', myserver]
+ return subprocess.Popen(command_arguments, shell=False)
+
+print(ping_secure('8.8.8.8'))
diff --git a/Python Tools/Web Penetration/writing_file_temp_secure.py b/Python Tools/Web Penetration/writing_file_temp_secure.py
new file mode 100644
index 0000000..0c8c63c
--- /dev/null
+++ b/Python Tools/Web Penetration/writing_file_temp_secure.py
@@ -0,0 +1,9 @@
+from tempfile import NamedTemporaryFile
+
+def write_results(results):
+ filename = NamedTemporaryFile(delete=False)
+ print(filename.name)
+ filename.write(bytes(results,"utf-8"))
+ print("Results written to", filename)
+
+write_results("writing in a temp file")
diff --git a/Python Tools/Web Penetration/yaml_secure.py b/Python Tools/Web Penetration/yaml_secure.py
new file mode 100644
index 0000000..6b21edf
--- /dev/null
+++ b/Python Tools/Web Penetration/yaml_secure.py
@@ -0,0 +1,7 @@
+import os
+import yaml
+user_input = input()
+with open(user_input) as secure_file:
+ contents = yaml.safe_load(secure_file) # secure
+ print(contents)
+