7

I have a Moto G3 Turbo with Android 6.0.1 Marshmallow. I use the phone to make wifi hotspot so I can use internet on my laptop.

I was able to do a successful Metasploit over WAN/Internet, and for that I need to port-forward to my laptop. But the problem is, I don't have any modern or router to actually go to setting login with admin password or anything like that.

What can I do? Is there any app that can do this and whether it need to root permission?

  • 1
    Generally you can't, not because Android isn't capable, but because in general carriers don't allow inbound traffic of any kind to mobile devices. You may get an IP address from your carrier, but that is just for outbound traffic, unsolicited inbound traffic (the kind you need port forwarding for) is nearly always blocked by every carrier world-wide. Add to that most carriers don't give you a public IP anyway, so even if you did get port forwarding to work, you likely couldn't use it. – acejavelin Feb 4 '17 at 14:46
  • That's not true, if your application could not receive inbound traffic how you getting message to your phone. – Shawn Thomas Rheal Nov 2 '17 at 2:35
  • @ShawnThomasRheal by opening an outbound connection and keep it open for replies. That's what most apps use GCM for – so not every app has to keep its own connection open. – Izzy Nov 2 '17 at 7:18
1

In most cases you won't be able to make inbound connection when using Mobile Data because of CGNAT and firewalls at ISP level, as explained by acejavelin in comment. See this answer to know the problem in detail and how it can be worked around.

However if you can reach your phone from internet, extending this access to a connected host (PC in your case) is not a problem. Port forwarding is done with routers and when being used as a Wi-Fi hotspot, your phone is in fact acting as a router. In order to forward port, you need to do Destination Address Translation (DNAT) using Linux kernel's builtin firewall userspace tool iptables.

First make sure that kernel is configured to forward internet traffic (already set when hotspot is ON):

~# echo 1 >/proc/sys/net/ipv4/ip_forward

Let's say the IP address assigned by hotspot to PC is 192.168.43.10 and you want to forward SSH default port (22):

~# iptables -t nat -I PREROUTING -p tcp --dport 22 -j DNAT --to 192.168.43.10

This is the simplest form of Port Forwarding.

If default POLICY of FORWARD chain in FILTER table is not ACCEPT, define rules explicitly to accept the forwarded packets:

~# iptables -I FORWARD -p tcp -d 192.168.43.10 --dport 22 -j ACCEPT

Also accept outbound forwarded traffic if needed.

And yes, executing all above commands need root access.

SOURCE: NAT-HOWTO

protected by Community Jan 22 '18 at 21:44

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.