顯示具有 程式語言 標籤的文章。 顯示所有文章
顯示具有 程式語言 標籤的文章。 顯示所有文章

2013年3月26日 星期二

Creat a "programmer platform"

個人已經習慣在Unix 系列的平台下開發各種滲透工具程式,這下如果只能用“Windows暈倒”平台上開發,要如何將各種開發資源都放進去呢?其實是不難...

建議可以用VMware先安裝一個“乾淨的”Windows作業系統
1.記得系統做到完整的更新
2.安裝防毒軟體(Windows提供的 Microsoft Security Essentials 就可以加減用啦)


接下來就是安裝各種開發程式平台的瑣碎工作,下面是個人安裝的步驟與經驗,因此不代表一定要依此步驟安裝,可依個人喜好調整順序



1. JRE( Java SE Runtime Environment  )

下載點:Java SE Runtime Environment 7 Downloads



下載後,請依據程式的指示完成安裝.


2. 安裝 “Eclipse 開發平台“,當然有人並不建議,因為很肥很大,但是此 IDE的方便性,對初學者來說,應該是很有幫助的,不然一直要查Code Book蠻累的ㄡ...二來,它提供了多種平台(Windows, Unix, Mac...)

程式下載點:Eclipse 開發平台

該程式不需要執行"Setup 或是Install",只要有安裝JRE環境,並將檔案解壓縮到指定目錄就可以執行了


3.安裝 Python on Eclipse 
首先要先下載Python 的開環境程式,再將PyDev裝到Eclipse IDE裡面就可以用了

個人建議還是使用Python 2.7的版本,因為許多的滲透測試工具的原始碼都是2.6 or 2.7的版本

3.1 下載Python 2.7 並將其安裝起來



3.2 設定Eclipse 的Python 開發環境

首次開啟Eclipse IDE



設定工作目錄,請按下[Next]


請選擇[HELP]==>[Install New Software]

請按下[Add]



請輸入參數
Name:PyDev
Location: http://Pydev.org/updates











接下來請勾選PyDev 的選項,並依據指示安裝



接下來安裝程式會問一個認證的問題,也是給他勾起來,裝下去吧! 
如果過程沒有任何問題,這時應該就會顯示安裝完畢,並新啟動Eclipse囉

第一次使用Eclipse 開發Python 需要一些設定


請選擇[File] ==> [New] ==> [Other] ==>[PyDev Project]



請輸入一個Project Name:如Test
接下來要設定Python 直譯器的位置環境(很重要別漏了),請點選"Please configure an interpreter in the related ......"這個連結
請按下[New],並輸入Python 2.7 以及尋找Python 程式位置(一般是放在c:\Python27\python.exe)

請將所有選項打勾,並一路按下[OK],[OK]....就真的OK 安裝好了





下面就試著寫一個經典的"Hello Worle!" Python 版




嗯~~ 完成了!


4. 安裝c/c++ 開發環境,個人建議Dev C++就很好用了
安裝下載點: Dev C++




5. Unix Command 支援??
 完成開發程式環境安裝,但是好用的Bash怎麼辦呢? 好加在有 “cygwin”這個for Windows 的套件可以安裝,不過安裝的時間有點久,要耐心一點


下載點:Cygwin Setup
懶得打字了,我把所有安裝過程的畫面一步一步截圖下來,自己看吧


請點選桌面上的[Cygwin Terminal],啟動Cygwin



































2013年3月5日 星期二

POP 電郵帳密測試

用python 寫了一個小工具

POP_Test.py

import os,sys,string,email,poplib   

class Test_Mail():
    def __init__(self,server,username,passwd):
        self.servername = server 
        self.username = username
        self.passwd = passwd
        self.data = []

    def connect(self):
        try:
            self.pop = poplib.POP3(self.servername,110,3)
            self.pop.set_debuglevel (1)
            self.pop.user(self.username)
            self.pop.pass_(self.passwd)
            return True
        except:
            return False

if __name__ == "__main__":

account_file = open("account.txt", "r")
passwd_file = open("pass.txt", "r")
success_log = open("success.txt","w")

account_list = account_file.readlines()
passwd_list = passwd_file.readlines()

total=len(account_list)*len(passwd_list)

start_num = 0
for account in account_list:
    for passwd in passwd_list:
        start_num = start_num + 1
        rate = float(start_num) / float(total)   
        rate_num = int(rate * 100)  
        print "Process : "+"%d%%" % (rate_num)+"        ("+str(start_num)+"/"+str(total)+")"
        pop_server_ip="127.0.0.1"
        gm =Test_Mail(pop_server_ip,account.strip(),passwd.strip()) 
        if gm.connect():
            print "Test Success!"
            success_log.write(account.strip()+"  "+passwd.strip()+'\n')
            print"========================="
    
success_log.close() 
account_file.close()
passwd_file.close()

TCP Port Scan (Ruby版)

一般來講,許多的滲透測試專家大多會用nmap這一類的Port scan 工具,但是往往忽略了,使用該工具所產生的“噪音”(測試的封包量太大,且帶有特定的資訊),會讓防火牆與IDS容易偵測到,並且遭到阻絕或產生錯誤的偵測資訊.

因此,介紹另一個工具“Hping”給各位參考

hping 官方網頁

hping is a command-line oriented TCP/IP packet assembler/analyzer. The interface is inspired to the ping(8) unix command, but hping isn't only able to send ICMP echo requests. It supports TCP, UDP, ICMP and RAW-IP protocols, has a traceroute mode, the ability to send files between a covered channel, and many other features.

該工具好處,可以自定封包大小,測試次數...等,
例如:
要測試10.0.0.1  的 80 port是否開啟?
指令: sudo hping3 -S -c 1 10.0.0.1 -p 80


下面自己寫了一個Ruby的多線程版本

Scan.rb

#!/usr/bin/ruby

require 'target_gen.rb'
ip=gets()
scan_result=[]
threads = []
t=Time.now
xx=t.strftime("%Y%m%d-%H%M%S.txt")
myfile=File.new(xx, "w")


start_time=Time.new
my_hscan=Target_gen.new(ip,[23,25,80,110,143,443,1433,3306,3389,5800,5900,8080])
my_hscan.gethosts
my_hscan.getports
my_hscan.targets

(my_hscan.targets.size).times{|i|
  threads << Thread.new(i) { |j|
    scan_result[i] = `#{my_hscan.targets[i]}`
  }
}

threads.each { |aThread|  aThread.join }


print"==============================================================\n"
print"==                    Hping Scan Report                     ==\n"
print"==                      Written by james  Lai       Ver 0.12   ==\n"
print"==============================================================\n"
print "Targets: "+ip.chomp+".1/24\n"
puts "Targets_number: "+my_hscan.gethosts.length.to_s()
puts "Targets_ports: "+my_hscan.getports.length.to_s()
puts "Times:"+my_hscan.targets.length.to_s()
print"==============================================================\n"

myfile.puts("==============================================================\n")
myfile.puts("=========================    Scan Report   ===================\n")
myfile.puts("==============================================================\n")
myfile.puts( "Targets: "+ip.chomp+".1/24\n")
myfile.puts( "Targets_number: "+my_hscan.gethosts.length.to_s())
myfile.puts("Targets_ports: "+my_hscan.getports.length.to_s())
myfile.puts( "Times:"+my_hscan.targets.length.to_s())
myfile.puts("==============================================================\n")

(scan_result.size).times{|i|
if (scan_result[i].match("flags=SA") != nil) and(scan_result[i].match("id=0") == nil)

result=(scan_result[i].gsub("DF","")
ss=result.split(" ")
result = ss[13]+" "+ss[14]+" "+ss[15]+" "+ss[16]+" "+ss[17]+" "+ss[18]+" "+ss[19]

myfile.puts(result.to_s())

end
}

print"==============================================================\n"
puts "Start: "+ start_time.to_s()
stop_time=Time.now
puts "Stop : "+ stop_time.to_s()
puts "Scantime: "+(stop_time-start_time).to_s()+"sec"
print"==============================================================\n"

myfile.puts("==============================================================\n")
myfile.puts("Start: "+ start_time.to_s())
myfile.puts( "Stop : "+ stop_time.to_s())
myfile.puts( "Scantime: "+(stop_time-start_time).to_s()+"sec")
myfile.puts("==============================================================\n")
myfile.close





target_gen.rb


class Target_gen
  def initialize(hosts, ports)
    @a_hosts = hosts
    @a_ports = ports
    @scan_ip=[]
    @scan_str=[]
  end
  
  def getports
  @a_ports.each_index{|i|
j = rand(i+1)
@a_ports[i], @a_ports[j] = @a_ports [j] , @a_ports [i]
}
    return @a_ports 
  end
  def gethosts
@scan_ip = (1..255).to_a
@scan_ip.each_index{|i|
j = rand(i+1)
@scan_ip[i], @scan_ip[j] = @scan_ip [j] , @scan_ip [i]
}
(@scan_ip.size).times{|i|
@scan_ip[i] = @a_hosts.chomp+"."+@scan_ip[i].to_s()
}
    return @scan_ip 
  end 
  
  def targets
nums=0 
(@a_ports.size).times{|i|
(@scan_ip.size).times{|j|
@scan_str[nums] = "sudo hping3 -S -c 1 "+@scan_ip[j].to_s()+" -p "+@a_ports[i].to_s()
nums=nums+1
}
}
return @scan_str
  end
  
end





用APNIC找出台灣所有的IP位址