Skip to content

Conversation

royari
Copy link
Contributor

@royari royari commented Oct 5, 2019

#61 I tried to clean up a little bit, let me know if this is what you had in mind. I can make more changes if required.

@alichtman
Copy link
Owner

alichtman commented Oct 6, 2019

I meant something more along the lines of defining methods that perform actions, such as:

def disable_sshd():
	sp.run whatever

And then calling that in the lockdown and interactive sequences instead of the literal subprocess command.


# Get sudo priv
sp.run("sudo -E -v", shell=True, stdout=sp.PIPE)
run_command("sudo -E -v")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful... You lost a shell=True on this line that's really important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I explicitly didn’t want to invoke the shell through shell=True to avoid shell injection vulnerability. I tried it out through the interpreter and run_command("sudo -E -v") executes. Please let me know if I am misunderstanding the shell=True argument. Also, I'll try and define methods to perform actions.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explicitly didn’t want to invoke the shell through shell=True to avoid shell injection vulnerability.

I don't think there is a way to exploit this particular shell=True since there's no user input besides the sudo password. You're right to be careful though.

Take a look at the example here: https://docs.python.org/2/library/subprocess.html#frequently-used-arguments

I remember not being able to get it to work without that shell=True but it has been a very long time since I sat down with this code. I'll find some time to mess with it soon.

Comment on lines +307 to +314
run_command("sudo launchctl load /System/Library/LaunchDaemons/com.apple.alf.agent.plist")
run_command("sudo launchctl load /System/Library/LaunchAgents/com.apple.alf.useragent.plist")
run_command("sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on")
run_command("sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setloggingmode on")
run_command("sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on")
run_command("sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setallowsigned off")
run_command("sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setallowsignedapp off")
run_command("sudo pkill -HUP socketfilterfw")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor looks good to me. Strings in favor of lists.

sp.run(['sudo', '/usr/libexec/ApplicationFirewall/socketfilterfw', '--setallowsigned', 'off'], stdout=sp.PIPE)
sp.run(['sudo', '/usr/libexec/ApplicationFirewall/socketfilterfw', '--setallowsignedapp', 'off'], stdout=sp.PIPE)
sp.run(['sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.captive.control Active -bool false'], stdout=sp.PIPE)
run_command("sudo spctl --master-enable")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lost another shell=True.

run_command("defaults write com.apple.screensaver askForPasswordDelay -int 0")
run_command("defaults write NSGlobalDomain AppleShowAllExtensions -bool true")
run_command("defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false")
run_command("defaults write com.apple.finder AppleShowAllFiles -boolean true")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing shell=True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants