diff --git a/PKG-INFO b/PKG-INFO index 4d5be6a..31973ba 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pwn-ckyan -Version: 2.1.3 +Version: 2.1.4 Summary: pwnScript Home-page: https://github.com/c0mentropy/ckyan.pwnScript Author: Comentropy Ckyan diff --git a/README.md b/README.md index 630e505..11fe90a 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,18 @@ - 增加了本地调试`--tmux`参数,使你在写脚本时打的断点`D()`,不需要一直注释和取消注释,而只有在你调用该参数时才会触发进入debug调试,不调用该参数即不会进入调试,无须频繁更改该注释了。 - 完善了对pwntools常用指令的封装。 -- 将AE64的脚本添加到项目中,而无须进行提前安装。 +- 讲AE64的脚本添加到项目中,而无须进行提前安装。 - 修复了部分已知bug。 +2.1.4新增功能: + +- 使用`pwnScript new exp.py --name ckyan`生成初始化脚本,主要是一些基本信息和注释之类的。 +- 修改了无法使用`pwnScript debug --file ./pwn`直接交互的bug。 + + + ## 快速上手 脚本基于`pwntools`,`ae64`开发,所以只需要安装所需库即可使用。 @@ -72,6 +79,8 @@ https://github.com/veritas501/ae64.git pip install . ``` +或 + ```bash pip install pwn-ckyan-2.1.1.tar.gz ``` @@ -567,6 +576,12 @@ if __name__ == '__main__': +### qemu + + + + + ## 其它 水平一般,代码很烂,如有bug,欢迎吐槽。但希望不要言语攻击QAQ,骂了就哭 :( diff --git a/ckyan/pwnScript/args_parser/__init__.py b/ckyan/pwnScript/args_parser/__init__.py index 5124491..66dd532 100644 --- a/ckyan/pwnScript/args_parser/__init__.py +++ b/ckyan/pwnScript/args_parser/__init__.py @@ -1,8 +1,19 @@ import argparse +from .generation_init_script import generation_script from ..log4ck import * +PWN_SCRIPT_NAME = r""" + _ ____ _ _ + ___| | ___ _ __ _ _ __ _ ____ ___ __ / ___| ___ _ __(_)_ __ | |_ + / __| |/ / | | |/ _` | '_ \ | '_ \ \ /\ / / '_ \\___ \ / __| '__| | '_ \| __| +| (__| <| |_| | (_| | | | |_| |_) \ V V /| | | |___) | (__| | | | |_) | |_ + \___|_|\_\\__, |\__,_|_| |_(_) .__/ \_/\_/ |_| |_|____/ \___|_| |_| .__/ \__| + |___/ |_| |_| + PwnScript version: 2.1.4""" + "\n\n" + + class CliParser: def __init__(self): self.local = True @@ -16,7 +27,7 @@ def __init__(self): def set_parse_arguments(self): - VERSION = "PwnScript: version 2.1.3\n" \ + VERSION = "PwnScript: version 2.1.4\n" \ "Author: Comentropy Ckyan\n" \ "Email: comentropy@foxmail.com\n" \ "GitHub: https://github.com/c0mentropy/ckyan.pwnScript\n" @@ -30,9 +41,6 @@ def set_parse_arguments(self): subparsers = parser.add_subparsers(dest='Commands', help='Available Commands') - # 添加 "run" 命令 - auto_parser = subparsers.add_parser('auto', aliases=['run'], help='Automatically detect attacks') - # 添加 "debug" 命令 de_parser = subparsers.add_parser('debug', aliases=['de'], help='Attack locally') de_parser.add_argument('-f', '--file', type=str, help='File to debug') @@ -49,9 +57,20 @@ def set_parse_arguments(self): re_parser.add_argument('-f', '--file', type=str, help='File to debug') re_parser.add_argument('-l', '--libc', type=str, help='File to debug') + # 添加 "run" 命令 + auto_parser = subparsers.add_parser('auto', aliases=['run'], help='Automatically detect attacks') + # 添加 "blasting" 命令 bl_parser = subparsers.add_parser('blasting', aliases=['bl'], help='Attack blow up') + # 添加 "new_file" 命令 + generation_file = subparsers.add_parser('generation', aliases=['new'], help='Generate the initialization script') + + # 添加文件名参数 + generation_file.add_argument("filename", help="The name of the file to create") + # 添加 name 参数 + generation_file.add_argument("-n", "--name", help="The username to use in the initialization script") + # 解析命令行参数 args = parser.parse_args() @@ -61,7 +80,15 @@ def set_parse_arguments(self): exit() # 根据子命令进行不同的处理 - if args.Commands in ['de', 'debug']: + if args.Commands in ['auto', 'run'] or args.Commands in ['blasting', 'bl']: + return + + elif args.Commands in ['generation', 'new']: + file_name = args.filename + author_name = args.name + generation_script(file_name=file_name, author_name=author_name) + + elif args.Commands in ['de', 'debug']: self.local = True self.binary_path = args.file @@ -108,4 +135,8 @@ def get_parse_arguments(self): return self.local, self.binary_path, self.ip, self.port, self.remote_libc_path -cli_parser = CliParser() +def args_init() -> CliParser: + return CliParser() + + +# cli_parser = args_init() diff --git a/ckyan/pwnScript/args_parser/generation_init_script.py b/ckyan/pwnScript/args_parser/generation_init_script.py new file mode 100644 index 0000000..6a8a629 --- /dev/null +++ b/ckyan/pwnScript/args_parser/generation_init_script.py @@ -0,0 +1,61 @@ +def generation_script(*, file_path: str = './', file_name: str = "exp.py", author_name: str = 'ckyan'): + import os + from datetime import datetime + from ..log4ck import success + + if file_name is None: + file_name = "exp.py" + + if author_name is None: + author_name = 'ckyan' + + script_format = f''' +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Author: {author_name} +Generation date: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")} +""" + +""" +GitHub: + https://github.com/c0mentropy/ckyan.pwnScript +Help: + python3 exp.py --help + python3 exp.py debug --help + python3 exp.py remote --help +Local: + python3 exp.py debug --file ./pwn +Remote: + python3 exp.py remote --ip 127.0.0.1 --port 9999 [--file ./pwn] [--libc ./libc.so.6] + python3 exp.py remote --url 127.0.0.1:9999 [--file ./pwn] [--libc ./libc.so.6] +""" + +# ./exp.py de -f ./pwn +# ./exp.py re -f ./pwn -u "" + +from ckyan.pwnScript import * + +def exp(): + pandora_box.init_script() + + elf = pandora_box.elf + libc = pandora_box.libc + p = pandora_box.conn + + +if __name__ == '__main__': + exp() + '''.strip() + + result_file = os.path.join(file_path, file_name) + + # 打开文件并写入字符串 + with open(result_file, "w") as file: + file.write(script_format + "\n") + + success("File generated.") + + exit() + diff --git a/ckyan/pwnScript/connect/__init__.py b/ckyan/pwnScript/connect/__init__.py index 7508e35..075f176 100644 --- a/ckyan/pwnScript/connect/__init__.py +++ b/ckyan/pwnScript/connect/__init__.py @@ -1,4 +1,5 @@ from pwn import * + from ..args_parser import * from ..log4ck import * from ..exception_message import exception_message @@ -36,7 +37,7 @@ def set_connect_parameter(self): self.libc = self.elf.libc context.binary = self.binary_path - self.conn = process(self.binary_path) + self.conn = process([self.binary_path]) else: error(exception_message.file_not_exist) else: @@ -124,6 +125,8 @@ def update_script(self, local: bool = True, context.log_level = "debug" context.terminal = ['tmux', 'splitw', '-h'] +cli_parser = args_init() + connect_io = ConnectIO(cli_parser.local, cli_parser.binary_path, cli_parser.ip, @@ -134,3 +137,14 @@ def update_script(self, local: bool = True, pandora_box = connect_io # connect_io.set_connect_parameter() +if 'pwnScript' in sys.argv[0]: + if cli_parser.local and cli_parser.binary_path is not None: + try: + connect_io.init_script() + if cli_parser.tmux: + gdb.attach(connect_io.conn) + pause() + connect_io.conn.interactive() + except Exception as ex: + error(f"{str(ex) = }") + exit() diff --git a/ckyan/pwnScript/debugger/__init__.py b/ckyan/pwnScript/debugger/__init__.py index 7ad31e0..abba0c5 100644 --- a/ckyan/pwnScript/debugger/__init__.py +++ b/ckyan/pwnScript/debugger/__init__.py @@ -17,7 +17,7 @@ def ggdb(break_point: str = "", pie: int = 0): os.system("chmod +x ./gdb.sh") -def gdb_debugger(*, break_point: str = "", binary_path: str = connect_io.binary_path, enable_pie: bool = False) -> None: +def gdb_debugger(*, break_point: str = "", binary_path: str = "", enable_pie: bool = False) -> None: """ Creates a GDB debugging script based on the provided parameters and makes it executable. @@ -25,6 +25,10 @@ def gdb_debugger(*, break_point: str = "", binary_path: str = connect_io.binary_ :param binary_path: The path to the binary file being debugged. :param enable_pie: A boolean indicating whether to enable Position Independent Executables (PIE) support. """ + + if binary_path == '': + binary_path = connect_io.binary_path + # Ensure input parameters are safe and valid if not binary_path: print("Invalid break_point or binary_path.") @@ -64,5 +68,5 @@ def ddebug(): D = ddebug -if connect_io.local: +if '.py' in sys.argv[0] and connect_io.local: gdb_debugger() diff --git a/setup.py b/setup.py index 1d5639d..71e7e3a 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup( name = 'pwn-ckyan', - version = '2.1.3', + version = '2.1.4', author = 'Comentropy Ckyan', author_email = "comentropy@foxmail.com", description = "pwnScript", @@ -20,7 +20,7 @@ ], entry_points={ 'console_scripts': [ - 'pwnScript=ckyan.pwnScript:args_parser' + 'pwnScript=ckyan.pwnScript.args_parser:args_init' ], }, )