Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #199 from oliverlavery/fix-su-quoting
Browse files Browse the repository at this point in the history
Fix su quoting
  • Loading branch information
Re4son authored Apr 17, 2019
2 parents 2b2c8de + 24cf75b commit 355b8c0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
1 change: 0 additions & 1 deletion assets/scripts/bootkali
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ SCRIPT_PATH=$(readlink -f $0)
if [ $# -eq 0 ]; then
$busybox chroot $mnt /bin/bash -c "if [ ! -f $HOME/.hushlogin ]; then touch $HOME/.hushlogin; fi; /bin/login -f root"
else

#APACHE

if [ "$1" == "apache" ] && [ "$2" == "start" ]; then
Expand Down
4 changes: 3 additions & 1 deletion assets/scripts/bootkali_init
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ else
exit 1
fi


## No longer needed as SELinux is set to permissive mode via "10setenforce" init script.
#su -c setenforce 0
#su -c 'setenforce 0'


######### CHECK FOR ROOT #########
f_checkforroot(){
Expand Down
8 changes: 6 additions & 2 deletions src/com/offsec/nethunter/CustomCommandsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -31,6 +32,7 @@
import java.util.List;

import androidx.appcompat.app.AlertDialog;
import android.widget.SearchView;
import androidx.fragment.app.Fragment;

//import androidx.appcompat.widget.SearchView;
Expand Down Expand Up @@ -119,19 +121,21 @@ private void addToBoot(CustomCommand command) {
String _cmd = command.getCommand();
//String _mode = command.getExec_Mode();
String _sendTo = command.getSend_To_Shell();
nh = new NhPaths();

String composedCommand;
if (_sendTo.equals("KALI")) {
composedCommand = "su -c bootkali custom_cmd " + _cmd;
composedCommand = "su -c '"+nh.APP_SCRIPTS_PATH+"/bootkali custom_cmd " + _cmd + "'";
} else {
// SEND TO ANDROID
// no sure, if we add su -c , we cant exec comands as a normal android user
composedCommand = _cmd;
}
String bootServiceFile = bootScriptPath + "/" + custom_commands_runlevel + "_" + command.getId() + "_custom_command";
String fileContents = shebang + _label + "\n" + composedCommand;
Log.d("bootScript", fileContents);
exe.RunAsRoot(new String[]{
"echo '" + fileContents + "' > " + bootServiceFile,
"cat > " + bootServiceFile + " <<s0133717hur75\n" + fileContents + "\ns0133717hur75\n",
"chmod 700 " + bootServiceFile
});

Expand Down
3 changes: 2 additions & 1 deletion src/com/offsec/nethunter/KaliServicesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ public int getCount() {
private void addBootService(int serviceId) {
String bootServiceFile = bootScriptPath + "/" + services[serviceId][4];
String fileContents = shebang + services[serviceId][0] + "\n" + services[serviceId][2];
Log.d("bootScript", fileContents);
exe.RunAsRoot(new String[]{
"echo '" + fileContents + "' > " + bootServiceFile,
"cat > " + bootServiceFile + " <<s0133717hur75\n" + fileContents + "\ns0133717hur75\n",
"chmod 700 " + bootServiceFile
});

Expand Down
4 changes: 3 additions & 1 deletion src/com/offsec/nethunter/gps/LocationUpdateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import android.os.Bundle;
import android.os.IBinder;
import android.os.StrictMode;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
Expand Down Expand Up @@ -241,7 +244,6 @@ public void onLocationChanged(Location location) {
Log.d(TAG, "NMEA update: "+nmeaSentence);
out.println(nmeaSentence);


if (updateReceiver != null) {
if (firstupdate) {
firstupdate = false;
Expand Down
14 changes: 7 additions & 7 deletions src/com/offsec/nethunter/service/RunAtBootService.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ protected void onHandleWork(@NonNull Intent intent) {
_res = x.RunAsRootOutput(command);

if (_res.equals("1")) {
Toast.makeText(getBaseContext(), getString(R.string.toastchrootmountedwarning), Toast.LENGTH_LONG).show();
// Toast.makeText(getBaseContext(), getString(R.string.toastchrootmountedwarning), Toast.LENGTH_LONG).show();
doNotification(getString(R.string.toastchrootmountedwarning));
} else {
doNotification(getString(R.string.toastdeletingchroot));
Toast.makeText(getBaseContext(), getString(R.string.toastdeletingchroot), Toast.LENGTH_LONG).show();
/// Toast.makeText(getBaseContext(), getString(R.string.toastdeletingchroot), Toast.LENGTH_LONG).show();
x.RunAsRootOutput("su -c 'rm -rf " + nh.NH_SYSTEM_PATH + "/*'");
// remove the sp so we dont remove it again on next boot
sharedpreferences.edit().remove(ChrootManagerFragment.DELETE_CHROOT_TAG).apply();
sharedpreferences.edit().remove(ChrootManagerFragment.CHROOT_INSTALLED_TAG).apply();

Toast.makeText(getBaseContext(), getString(R.string.toastdeletedchroot), Toast.LENGTH_LONG).show();
// Toast.makeText(getBaseContext(), getString(R.string.toastdeletedchroot), Toast.LENGTH_LONG).show();
doNotification(getString(R.string.toastdeletedchroot));

}
Expand All @@ -117,13 +117,13 @@ protected void onHandleWork(@NonNull Intent intent) {
_res = x.RunAsRootOutput(command);

if (_res.equals("1")) {
Toast.makeText(getBaseContext(), getString(R.string.toastchrootmountedwarning), Toast.LENGTH_LONG).show();
// Toast.makeText(getBaseContext(), getString(R.string.toastchrootmountedwarning), Toast.LENGTH_LONG).show();
doNotification(getString(R.string.toastchrootmountedwarning));
} else {
doNotification("Starting chroot migration...");
Toast.makeText(getBaseContext(), getString(R.string.toastmigratingchroot), Toast.LENGTH_LONG).show();
// Toast.makeText(getBaseContext(), getString(R.string.toastmigratingchroot), Toast.LENGTH_LONG).show();
x.RunAsRootOutput("su -c 'mv " + nh.OLD_CHROOT_PATH + " " + nh.NH_SYSTEM_PATH + "'");
Toast.makeText(getBaseContext(), getString(R.string.toastmigratedchroot), Toast.LENGTH_LONG).show();
// Toast.makeText(getBaseContext(), getString(R.string.toastmigratedchroot), Toast.LENGTH_LONG).show();
sharedpreferences.edit().remove(ChrootManagerFragment.MIGRATE_CHROOT_TAG).apply();
doNotification(getString(R.string.toastmigratedchroot));
}
Expand Down Expand Up @@ -163,7 +163,7 @@ private boolean userinit(Boolean ShouldRun) {
// Toast.makeText(getBaseContext(), getString(R.string.autorunningscripts), Toast.LENGTH_SHORT).show();
return true;
}
Toast.makeText(getBaseContext(), getString(R.string.toastForNoBusybox), Toast.LENGTH_SHORT).show();
// Toast.makeText(getBaseContext(), getString(R.string.toastForNoBusybox), Toast.LENGTH_SHORT).show();
doNotification(getString(R.string.toastForNoBusybox));
return false;
}
Expand Down

0 comments on commit 355b8c0

Please sign in to comment.