How to start a Frida server from cmd?

506 Views Asked by At

I'm trying to start Frida from Windows cmd but its hanging and not proceeding to the second & command:

>adb -s 127.0.0.1:16480 shell "/mnt/shared/frida-server &" & frida -U -n system_server -l C:\Users\Documents\script.js

My intention is to avoid entering in shell with adb shell and then command

because im trying to start the server and call the hook from a single command.

But even entering on shell i still dont understand how to start/leave the server running on background and return:

>adb shell
SM-G7810:/ # /mnt/shared/frida-server &
[1] 2743
127|SM-G7810:/ # exit
You have running jobs
127|SM-G7810:/ #
2

There are 2 best solutions below

2
On

On Windows cmd, you can use the start command to run a process in the background and not wait for its completion. In your case, you can modify your command like this:

start adb shell "chmod 755 /data/data/android/test" && start adb shell "/data/data/android/test"

This will start both commands in the background, and the cmd prompt won't wait for their completion. The start command is used to open a new command prompt window for running the specified command. keep in mind that if the first command chmod 755 /data/data/android/test fails, the second command may still be executed. If you want to ensure that the second command is executed only if the first one succeeds, you might need to use a more sophisticated script or batch file , However If you're running this from a script or batch file, you might also want to consider using the call command to ensure that the script continues after the completion of the commands:

call adb shell "chmod 755 /data/data/android/test" && call adb shell "/data/data/android/test"

with that the script will continue to execute the next command even if the first one fails

Update

consider using the start command with the /B switch. This will start the command without opening a new window. example:

start /B adb shell "chmod 755 /data/data/android/test" && adb shell "/data/data/android/test"

The /B switch is used to start the command without opening a new window. This should allow the command to run in the background, and the Command Prompt won't wait for it to complete.

2
On

you can append &, at the end of shell commands. Which will run your command in the background and initiate a separate process for it

Proper command to run both of them in background would be

adb shell "(chmod 755 /data/data/android/test && /data/data/android/test)" &

Excerpt from this page:

Using an & at the end of a command starts the command in the background. The shell forks a child process, executes the command program, and then does not wait for the command to complete. Some daemons must be started this way in order to allow the invoking shell script (such as /etc/rc) to continue. cron does not need to be started with an & because it forks itself to create the child process, which continues running while the cron parent process returns to the invoker such as /etc/rc. If the script does /usr/sbin/cron, the shell will spawn the cron program to create a child process, and then the cron program will fork a child process to run the daemon independently. The cron command returns to the shell, and the script continues.

Update:

My answer was for the original question, before @luma edited their question to be more frida specific