Showing posts with label BCM96338. Show all posts
Showing posts with label BCM96338. Show all posts

Thursday, December 18, 2008

Customizing BCM96338 (3)

Eventually I found some time to complete it.

We now know

1. How to enter the modem
2. What settings need to be made to forward a port

Now, we will see how to automate this.

Automating this is very simple. I used expect to do this job.

I can directly post all the scripts here. But they are too long and the same expect scripts might not work for someone else.

First you need to manually make the settings at the modem.
Then, just follow the steps below

1. autoexpect telnet 192.168.1.1
1.1 When you get the login prompt, login by giving the user-name and password.
1.2 At the prompt type "sh" and get a shell.
1.3 At the shell type "iptables -L -t nat"
1.4 Once you see the o/p, press "Ctrl-D", , 14
1.5 This will take you out of the modem
1.6 Auto expect would have now created a script to do this (script.exp)

2. Edit the script, set force_conservative 1, rename it to something else (poke.exp in my case)

3. Repeat step 1. At 1.3, instead of listing the table, enter the DNAT command (Eg. iptables -t nat -I PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.1.10)

4. Repeat step 2, save it in some other name (ipt.exp in my case)

5. Now extract the rule from the poke.exp and save it in a file. It will look like something like this,
DNAT tcp -- anywhere anywhere tcp dpt:www to:192.168.1.10
Save it to a file (grep)

6. It is time to create a script (monitor.sh). RUNDIR is where all your files will be kept.

#!/bin/bash

RUNDIR=/root/bin/bsnl
${RUNDIR}/poke.exp > ${RUNDIR}/op
grep -q -- "`cat ${RUNDIR}/grep`" ${RUNDIR}/op || ${RUNDIR}/ipt.exp

7. Now you can add this to your crontab using the command "crontab -e"
*/5 * * * * /root/bin/monitor.sh
(Save and quit)

It won't be complete if I don't mention about ddns. Get an account there. This modem has a ddns client. Once you enable this, you can access your machine using the name that you got from dyndns. (I have actually done this also using a script since I maintain my dns records at zoneedit.com. More about it in another post)

Thursday, September 25, 2008

Customizing BCM96338 (2)

Its after a long time I got time to re-visit this topic. First let me give you the iptables rules to forward the connection.

Step 1: Find your external interface
Do a "ifconfig". You will see an array of devices. One of this will have your global ip.
(Check the index page of your device if you are doubtful about which one is the global ip. You can find your global ip there)

Step 2: iptables rules
iptables -t nat -I PREROUTING -p tcp --dport 22 -i ppp_0_35_2 -j DNAT --to 192.168.1.100
iptables -t filter -I FORWARD -p tcp --dport 22 -d 192.168.1.100 -j ACCEPT

ppp_0_35_2 -> Replace this with the name of your external interface
192.168.1.100 -> Replace this with the ip of your local ssh server

Step 3: How to forward for other connections?
Say you want to have external access to a web server running inside your local network. All that you have to do is issue the above to commands with following differences.

1) --dport 22 will change to --dport 80
2) 192.168.1.100 will be replaced with the ip of your local web server.

If you have any other service running inside, use the portocol (tcp/udp), port and ip of that service.

Wednesday, July 30, 2008

Customizing BCM96338 (1)

First of all, a big thanks to Google and http://www.cyberciti.biz/tips/hacking-beetel-220x-adsl-router-broadcom-bcm6338.html

Once you are in (Ok, if you haven't opened that page till now, telnet to device, login as admin, enter 'sh' as the option), explore the device file system. Go to bin and do a echo *

You will find that there are iptables and a bunch of other applications that we can use. In the coming posts I will explain how to setup the iptable rules to forward a connection coming from outside to a host within your local network.

Well, this could have been achieved by setting up a DMZ or NAT from the webpage. Unfortunately, these did not work for me. This is the only reason that I am forced to try my luck with iptables.