CSAW 2017 CVV及tabIEZ Writeup

因為需要準備出差, 只做了一些小題

CVV

信用卡號碼算算號器和隨機生成器
https://zh.wikipedia.org/zh-hans/Luhn%E7%AE%97%E6%B3%95
從網(wǎng)上找的代碼,有問題按照Luhn代碼算法說明改

代碼很爛,都是粘的還有錯。。。

#!/usr/bin/env python

# author: garbu

from random import randint
from pwn import *

def generate_card(type):
    """
    Prefill some values based on the card type
    """
    card_types = ["americanexpress","visa11", "visa16","mastercard","discover"
    
    def prefill(t):
        # typical number of digits in credit card
        def_length = 16
        
        """
        Prefill with initial numbers and return it including the total number of digits
        remaining to fill
        """
        if 'num:' in t:
            return [int(t[4]), int(t[5]), int(t[6]), int(t[7])], 12
        if t == card_types[0]:
            # american express starts with 3 and is 15 digits long
            # override the def lengths
            return [3, randint(4,7)], 13
            
        elif t == card_types[1] or t == card_types[2]:
            # visa starts with 4
            if t.endswith("16"):
                return [4], def_length - 1
            else:
                return [4], 10
            
        elif t == card_types[3]:
            # master card start with 5 and is 16 digits long
            return [5, randint(1,5)], def_length - 2
            
        elif t == card_types[4]:
            # discover card starts with 6011 and is 16 digits long
            return [6, 0, 1, 1], def_length - 4
            
        else:
            # this section probably not even needed here
            return [], def_length
    
    def finalize(nums):
        """
        Make the current generated list pass the Luhn check by checking and adding
        the last digit appropriately bia calculating the check sum
        """
        check_sum = 0
        
        #is_even = True if (len(nums) + 1 % 2) == 0 else False
        
        """
        Reason for this check offset is to figure out whther the final list is going
        to be even or odd which will affect calculating the check_sum.
        This is mainly also to avoid reversing the list back and forth which is specified
        on the Luhn algorithm.
        """
        check_offset = (len(nums) + 1) % 2
        
        for i, n in enumerate(nums):
            if (i + check_offset) % 2 == 0:
                n_ = n*2
                check_sum += n_ -9 if n_ > 9 else n_
            else:
                check_sum += n
        if check_sum % 10 == 0:
            return nums + [0]
        return nums + [10 - (check_sum % 10) ]
    
    # main body
    t = type.lower()    
    initial, rem = prefill(t)
    so_far = initial + [randint(1,9) for x in xrange(rem - 1)]
    #print "Card type: %s, " % t
    cardnum = "".join(map(str,finalize(so_far))).strip('\n')
    print cardnum
    return cardnum


# # run - check
# generate_card("discover")
# generate_card("mastercard")
# generate_card("americanexpress")

# generate_card("visa13")
# generate_card("visa16")


def ck(nums):
    """
    Make the current generated list pass the Luhn check by checking and adding
    the last digit appropriately bia calculating the check sum
    """
    check_sum = 0
    
    is_even = True if ((len(nums) + 1 )% 2) == 0 else False
    
    """
    Reason for this check offset is to figure out whther the final list is going
    to be even or odd which will affect calculating the check_sum.
    This is mainly also to avoid reversing the list back and forth which is specified
    on the Luhn algorithm.
    """
    check_offset = (len(nums) + 1) % 2
    
    for i, n in enumerate(nums):
        i = int(i)
        n = int(n)
        if i == 0:
            if is_even:
                n_ = n*2
                check_sum += n_ -9 if n_ > 9 else n_
            else:
                check_sum += n
            continue;
        if (i + check_offset) % 2 == 0:
            n_ = n*2
            check_sum += n_ -9 if n_ > 9 else n_
        else:
            check_sum += n
    if check_sum % 10 == 0:
        return 0
    return 10 - (check_sum % 10)


def ck2(nums):
    digits = [int(i) for i in str(nums)]
    odd_digits = digits[-1::-2]
    even_digits = digits[-2::-2]
    total = sum(odd_digits)
    for digit in even_digits:
        total += sum([int(i) for i in str(2 * digit)])
    if total % 10 == 0:
        return "1"
    else:
        return "0"

conn = remote("misc.chal.csaw.io", 8308)
while True:
    cmd = conn.recvline()
    print cmd,

    if 'I need to know if ' in cmd:
        card = "".join(filter(str.isdigit, cmd))
        card = card[:-2]
        print card
        conn.sendline(ck2(card))
        conn.recvline()

    elif 'Visa' in cmd:
        conn.sendline(generate_card('visa16'))
    elif 'MasterCard' in cmd:
        conn.sendline(generate_card('mastercard'))
    elif 'Discover' in cmd:
        conn.sendline(generate_card('discover'))
    elif 'American Express' in cmd:
        conn.sendline(generate_card('americanexpress'))
    elif 'starts with' in cmd:
        num = generate_card("num:" + cmd[-6:-2])
        conn.sendline(num)
    elif 'ends with' in cmd and cmd[-4] in '01234567890':
        num = cmd[-6:-2]
        while True:
            card = generate_card('visa11') + '1' + num
            if ck(card[:-1]) == int(card[-1]):
                print card
                conn.sendline(card)
                break;
    elif 'ends with' in cmd:
        num = cmd[-3:-2]
        while True:
            card = generate_card('visa16')
            if card[-1] == num:
                conn.sendline(card)
                break;

    print conn.recvline(),
   

tabIEZ

Ascii值用表置換,長度不長直接手動查表逐位算出來的

tu.jpg
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,517評論 6 539
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 99,087評論 3 423
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 177,521評論 0 382
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,493評論 1 316
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,207評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,603評論 1 325
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,624評論 3 444
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,813評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 49,364評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,110評論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,305評論 1 371
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,874評論 5 362
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,532評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,953評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,209評論 1 291
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,033評論 3 396
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,268評論 2 375

推薦閱讀更多精彩內容

  • ¥關閉¥ 【雷霆戰(zhàn)機】 〖http://pan.baidu.com/s/1kVstszX〗 《解壓源碼后直接用AI...
    小菜c閱讀 9,497評論 0 19
  • ¥開啟¥ 【雷霆戰(zhàn)機】 〖http://pan.baidu.com/s/1kVstszX〗 《解壓源碼后直接用AI...
    小菜c閱讀 3,758評論 0 5
  • ¥開啟¥ 【雷霆戰(zhàn)機】 〖http://pan.baidu.com/s/1kVstszX〗 《解壓源碼后直接用AI...
    小菜c閱讀 3,568評論 1 10
  • ## 2015.06.05 - [開源利弊淺談 - 張超耀](移動組周技術分享總結#開源利弊淺談---張超耀) -...
    XcodeYang閱讀 1,504評論 1 3
  • Objective-C是一個動態(tài)語言,有一個c和匯編語言編寫的runtime庫(lib.objc.A.dylib)...
    link_hui閱讀 232評論 0 0