Skip to content

Commit

Permalink
Added the ability to create initialization scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
comentropy-ckyan committed Jun 4, 2024
1 parent e1c4ef3 commit 8cce7cc
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 13 deletions.
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`开发,所以只需要安装所需库即可使用。
Expand All @@ -72,6 +79,8 @@ https://github.com/veritas501/ae64.git
pip install .
```


```bash
pip install pwn-ckyan-2.1.1.tar.gz
```
Expand Down Expand Up @@ -567,6 +576,12 @@ if __name__ == '__main__':
### qemu
## 其它
水平一般,代码很烂,如有bug,欢迎吐槽。但希望不要言语攻击QAQ,骂了就哭 :(
Expand Down
43 changes: 37 additions & 6 deletions ckyan/pwnScript/args_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: [email protected]\n" \
"GitHub: https://github.com/c0mentropy/ckyan.pwnScript\n"
Expand All @@ -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')
Expand All @@ -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()

Expand All @@ -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

Expand Down Expand Up @@ -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()
61 changes: 61 additions & 0 deletions ckyan/pwnScript/args_parser/generation_init_script.py
Original file line number Diff line number Diff line change
@@ -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()

16 changes: 15 additions & 1 deletion ckyan/pwnScript/connect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pwn import *

from ..args_parser import *
from ..log4ck import *
from ..exception_message import exception_message
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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()
8 changes: 6 additions & 2 deletions ckyan/pwnScript/debugger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ 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.
:param break_point: The memory address or function name where the breakpoint should be set.
: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.")
Expand Down Expand Up @@ -64,5 +68,5 @@ def ddebug():

D = ddebug

if connect_io.local:
if '.py' in sys.argv[0] and connect_io.local:
gdb_debugger()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
description = "pwnScript",
Expand All @@ -20,7 +20,7 @@
],
entry_points={
'console_scripts': [
'pwnScript=ckyan.pwnScript:args_parser'
'pwnScript=ckyan.pwnScript.args_parser:args_init'
],
},
)
Expand Down

0 comments on commit 8cce7cc

Please sign in to comment.