Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for your grep script #13

Open
infamousrev opened this issue Aug 25, 2017 · 1 comment
Open

Solution for your grep script #13

infamousrev opened this issue Aug 25, 2017 · 1 comment

Comments

@infamousrev
Copy link

infamousrev commented Aug 25, 2017

The script located at:
https://github.com/MAVProxyUser/P0VsRedHerring/blob/master/grep

Does not work properly, it tries to activate adb, but logging in with adb won't work.

This is because the login script of adb runs grep in its initialisation (Causing Login->grep->restart-adb->failure).

I suggest either (this will activate adb quite late in boot):

echo /system/bin/adb_en.sh >> /system/bin/start_dji_system.sh

Or if you think that is too risky simply:

/system/bin/adb_en.sh&
/system/xbin/busybox nc -l -p 1234 -e /system/bin/sh&

Will offer a fairly risk free approach, however restoring grep function is an important thing to consider.

Or something like this:

#Mount system rw
mount -o remount,rw /system
#Select all lines before the debug check
cat /system/bin/start_dji_system.sh | /system/bin/grep -B10000 'setprop dji.sdrs 1' > /system/bin/start_dji_system.sh1
#Add line to activate adb
echo /system/bin/adb_en.sh > /system/bin/start_dji_system.sh2
#Select all lines after the debug check
cat /system/bin/start_dji_system.sh | /system/bin/grep -A10000 'setprop dji.sdrs_log 1' > /system/bin/start_dji_system.sh3
#Merge files
cat /system/bin/start_dji_system.sh1 /system/bin/start_dji_system.sh2 /system/bin/start_dji_system.sh3 > /system/bin/start_dji_system.sh4
#change permissions
chmod 755 /system/bin/start_dji_system.sh4
chown root:shell /system/bin/start_dji_system.sh4
#TODO: Add Sanity check
#replace restart script with modified variant
cp -a /system/bin/start_dji_system.sh4 /system/bin/start_dji_system.sh
@samuelsadok
Copy link

Another approach would be to make the grep hook transparent to the caller and launch custom startup code in a forked process. This way you can also safely make the hack persistent.

Like this:

self="$0"

# Comment these out to make RedHerring persistent
# mv /data/.bin/grep /data/.bin/grep.disarmed &>/dev/null
# self="/data/.bin/grep.disarmed"

/system/xbin/busybox touch /data/InYourGrill.$$

# If this is the first execution, restart myself in background with "--pwn" argument
if mkdir /tmp/RedHerring &>/dev/null; then
        mkdir /data/RedHerring &>/dev/null
        ( /system/xbin/busybox sh "$self" --pwn > /data/RedHerring/log.txt & )
fi

# Give control to the real grep unless started with --pwn
[ "$1" == "--pwn" ] || exec /system/xbin/busybox grep "$@"

### Beginning of persistent startup code ###

echo "### RED HERRING ###"
[start adb here]

However one thing puzzles me: there is actually no grep in $PATH, so it's not clear to me why anything would expect it to work in the first place.

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

No branches or pull requests

2 participants