Coder Social home page Coder Social logo

osniffer's People

Contributors

cooljiansir avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

wangyx0055

osniffer's Issues

1--How to use git?

Git----a better life!

When first time use git

    git config --global user.name xxxxx     #your name
    git config --global user.email [email protected]   #your email

fetch doc

    cd /home/workplace/ #/home/workplace is the directory you choose
    git init                #initialize
    git remote add origin https://github.com/cooljiansir/osniffer.git
    git fetch origin doc           #doc is the document branch,
    git checkout doc              #doc is the document branch
    ls                  #now you can see these documents!

push doc to the server

    cd /home/workplace      #the directory you choose
    git status              #see uncommited changes
    git add *               #if needed add some new files to git
    git commit -am "some comment..."    #commit your changes
    git push origin doc     #push your commit to the remote server

About the branchs

as the example above,we use doc branch,the same way to other branchs:

  • doc the document branch
  • web2 the html\css\js.... codes
  • master the cgi\server c code

3--WRTNode C helloworld!

WRTNode C helloworld!

Build the SDK

download http://pan.baidu.com/s/1pJ2XGa3 to /home/workplace

cd /home/workplace/
tar -xf dl_for_WRTnodeSDK140824.tar
tar -xf WRTnodeSDK140824.tar.bz2
mv dl WRTnodeSDK140824/
mv feeds.conf.default WRTnodeSDK140824/
cd WRTnodeSDK140824
make menuconfig
#select(y)          [*] Build the OpenWrt SDK  
make                 #wait about 1hour
cd bin/ramips/
cp OpenWrt-SDK-ramips-*.tar.bz2 /home/workplace/                  #It's the sdk!
cd /home/workplace
tar -xf OpenWrt-SDK-ramips-*.tar.bz2

compile our hello world .ipk

cd /home/workplace/OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/
cd package

download http://pan.baidu.com/s/1o61DNBW here

tar -xf helloworld.tar.bz2
cd ../
make 
cd bin/ramips/packages/
ls                 #here is helloworld_1_ramips_24kec.ipk

install to WRTnode and run !

scp helloworld_1_ramips_24kec.ipk [email protected]:/usr/bin/
ssh [email protected]
root@OpenWrt:~# cd /usr/bin
root@OpenWrt:/usr/bin# ls
root@OpenWrt:/usr/bin#  opkg install helloworld_1_ramips_24kec.ipk 
root@OpenWrt:/usr/bin# helloworld
a hellowrold ipk for openwrt !!!

6--How does sniffer work

How does sniffer work

Interfaces list

  • in html,js(jquery) $.getJSON( "/cgi-bin/OpenWrtSniffer?action=inter_list",function(data){});

           ↓             ↑

           ↓             ↑

           ↓             ↑

           ↓(http request)       ↑(http response)

           ↓             ↑

           ↓             ↑

           ↓             ↑
  • in wrtnode,uhttpd get the request and call /cgi-bin/OpenWrtSniffer

       see OpenWrtSniffer.c -> pcapfunc.h(pcapfunc.c)

           ↓             ↑

           ↓             ↑

           ↓             ↑

           ↓(use pipe send command) ↑(use pipe send result)

           ↓             ↑

           ↓             ↑

           ↓             ↑
  • OpenWrtSniffer send command to snifferd (using pipe),and get the result

       see snifferd.c -> pcapserver.h(pcapserver.c)

visit http://192.168.8.1:81/cgi-bin/OpenWrtSniffer?action=inter_list ,and you can see the json data

FrameWork

As the example above,osniffer use ajax to get data from our cgi program:

html(js)              uhttpd         OpenWrtSniffer           snifferd
   ||                   ||                                       ||
   ||---http request -->||                                       ||
   ||                   ||------ cgi ----> ||                    ||
   ||                   ||                 ||-----FIFO pipe----> ||
   ||                   ||                 ||<----FIFO pipe----- ||
   ||                   ||<--- printf ---- ||                    ||
   ||<--- json data --- ||                                       ||
   ||                   ||                                       ||

notice that the uhttpd and snifferd program runs all the time,but OpenWrtSniffer doesn't

Technologies

  • jQuery -- update UI
  • ajax -- js send http request without freshing the whole webpage
  • json -- data format supported by js
  • FIFO -- communicating with other process
  • libpcap API -- capture packets
  • libpthread API -- multi-thread programing

Question&Answer

the problems

In issue #4

make menuconfig

Q&a:

Q:Build dependency: Please install ncurses. (Missing libncurses.so or ncurses.h)
A:sudo apt-get install libncurses5-dev
Q:Build dependency: Please install GNU awk.
A:sudo apt-get install gawk
Q:Build dependency: Please install the subversion client.
A:sudo apt-get install subversion
Q:  scripts/config/mconf:命令未找到

In issue #4

make

Q&A:

checking for mipsel-openwrt-linux-gpg-error-config... /home/inu1255/桌面/WRTnodeSDK141114/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/bin/gpg-error-config
checking for GPG Error - version >= 1.8... ./configure: line 13829: /home/inu1255/桌面/WRTnodeSDK141114/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/bin/gpg-error-config: No such file or directory
./configure: line 13834: test: : integer expression expected
./configure: line 13837: test: : integer expression expected
no
configure: error: libgpg-error is needed.
                See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .
make[3]: *** [/home/inu1255/桌面/WRTnodeSDK141114/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libgcrypt-1.5.3/.configured_] Error 1
make[3]: Leaving directory `/home/inu1255/桌面/WRTnodeSDK141114/package/feeds/oldpackages/libgcrypt'
make[2]: *** [package/feeds/oldpackages/libgcrypt/compile] Error 2
make[2]: Leaving directory `/home/inu1255/桌面/WRTnodeSDK141114'
make[1]: *** [/home/inu1255/桌面/WRTnodeSDK141114/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.package_compile] Error 2
make[1]: Leaving directory `/home/inu1255/桌面/WRTnodeSDK141114'
make: *** [world] 错误 2

2--Use WRTnode as a web server

Use WRTnode as a web server

set ssh password first

  • power on wrtnode
  • wait for a while,and you'll see a AP called like"WRTnode9A0E"
  • connect it,password is 12345678
  • visit 192.168.8.1
  • login root with empty password
  • Go to System-> Administration and set the new password

config the uhttpd

ssh [email protected]
cd /etc/config/
vi uhttpd

add these lines to the rear

config uhttpd web               
        list listen_http 0.0.0.0:81
        option home /webroot/

then

cd /
mkdir webroot
cd webroot
echo 'hello openwrt world!'> index.html
reboot

Now wait for restart

and visit 192.168.8.1:81 and see what happens!

4--OpenWRT C CGI helloworld!

OpenWRT C CGI helloworld!

We don't want to install php on our OpenWRT since it's too big,We can write a small cgi in c(like php)

You must finish the No.2 and No.3 issue first

cd /home/workplace/OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2
cd package/helloworld/src/
vi helloworld.c    #content as follow
#include <stdio.h>
#include <stdio.h> //getenv

int main(void){
        printf("Content-Type: text/html\n\n");
        printf("GET:%s\n",getenv("QUERY_STRING"));
        return 0;
}
cd ../../../
make 
cd bin/ramips/packages/
scp helloworld_1_ramips_24kec.ipk [email protected]:/usr/bin
ssh [email protected]
cd /usr/bin
opkg install helloworld_1_ramips_24kec.ipk 
cd /webroot/
mkdir cgi-bin
cd cgi-bin
cp /bin/helloworld ./

visit http://192.168.8.1:81/cgi-bin/helloworld?helloworld=cgi

For more about cgi c ,refer to http://blog.csdn.net/kaloha3/article/details/8548027

5--Installing osniffer!

#5--Installing osniffer!

1 make the FIrmware and SDK

!!! attention : select libpcap NOT libcap

cd /home/workplace/
cd WRTnodeSDK140824/
make menuconfig
#[*] Build the OpenWrt SDK
# Libraries  ---> <*> libpcap............ Low-level packet capture library  --->
make 

2 Flush our Firmware

  • connect to wrtnode via wifi
  • visit 192.168.8.1
  • login
  • System -->Backup/Flash Firmware
  • Flash new firmware image --choose the /workplace/WRTnodeSDK140824/bin/ramips/openwrt-ramips-mt7620n-wrtnode-squashfs-sysupgrade.bin
  • Flash image
  • Flash Firmware - Verify --> Proceed
  • Wait for about 5 minutes

3 Compile for ipk

cd /workplace/WRTnodeSDK140824/bin/ramips/
tar -xf OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
cd OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/package
git clone -b master --single-branch https://github.com/cooljiansir/osniffer.git
cd ..
make
cd bin/ramips/packages 
scp OpenWrtSniffer_1_ramips_24kec.ipk [email protected]:/usr/bin/
ssh [email protected]
cd /usr/bin
opkg install OpenWrtSniffer_1_ramips_24kec.ipk 

4 Copy the web files

git clone -b web2 --single-branch https://github.com/cooljiansir/osniffer.git
cd osniffer
scp -r * [email protected]:/webroot/
ssh [email protected]
vi /etc/config/uhttpd 
#check if there are lines:,if not add them
config uhttpd web
        list listen_http 0.0.0.0:81
        option home /webroot/
/etc/init.d/uhttpd restart

Now visit 192.168.8.1:81 !

  • Capture --> Interfaces....
  • select any
  • Capture --> Capture Filters
  • enter 'arp ' in the first input there is a blank after arp
  • click set
  • Capture --> Go
  • click start
  • visit 192.168.8.12 and there are arp packets captured

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.