Cycle Scanner
Hello everyone , In this blog post , I will try to explain my solution steps for Cycle Scanner challenge from Mobile Hacking Lab Platform . i hope it will be useful for you
After install the app : my App GUI has a problem and i can’t access the button that enable the service use this command to enable the service :
adb shell am startservice com.mobilehackinglab.cyclicscanner/.scanner.ScanService

image.png let’s examine the
AndroidManifest.xml filewe found : Main Activity and the Service :Main Activity Structure :
handlePermissions():Checks if the app has permission to manage all files. If granted, calls
setupSwitch; otherwise, launches an intent to request the permission.
setupSwitch():handle enabling or disabling the scan service.
If switched on, starts the scan service and shows a toast message.
If switched off, displays a toast stating that the service cannot be stopped and forces the switch back to "on."
startService():Starts the scan service in the foreground and displays a toast indicating that the service has started . :
Scan Service Structure :
Service Lifecycle :
onCreate (): Initializes the handler thread (
HandlerThread) and sets up theServiceHandlerwith the new thread’sLooper.onStartCommand () : Starts the foreground notification and sends a message to
ServiceHandlerto begin scanning.onBind () : Returns
null, as this service does not support binding.
we have the channel_id :
ForegroundScanServiceChanneland the channel_nameScanServiceAccess the External Storage :
Environment.getExternalStorageDirectory()Retrieves the external storage directory using and checks if it is notnull.File externalStorageDirectoryrepresents the root directory of the external storage.
use
FilesKt.walkto look for Each file is checked for readability and whether it is a file.Scan Each File :
ScanEngine.INSTANCE.scanFile(file)to determine if the file is safe. Logs the result as either "SAFE" or "INFECTED”
ScanFile Function :
scans a given file to check whether its hash matches any known malware samples.
Uses
ProcessBuilderto execute the command in a shell.command("sh", "-c", command), redirecting the error stream to the standard output to the external storage .Read Command Output : Retrieves the output of the
toybox sha1sumcommandthen Extract Hash Value and Compare Hash Against Known Malware

attack here try to manipulate the object that created in the
AbsolutePathcreate a file that contain malicious code the upload the file and then launch the scan :
"nano test.txt ; touch kero"contain command"test.txt ; touch kero "and then upload it to the /sdcard/Downloadand here we success

Last updated