CSAW 2017 CVV及tabIEZ Writeup

因?yàn)樾枰獪?zhǔn)備出差, 只做了一些小題

CVV

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

代碼很爛土铺,都是粘的還有錯(cuò)蚤认。。甚淡。

#!/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值用表置換淤年,長度不長直接手動(dòng)查表逐位算出來的

tu.jpg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末苟蹈,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子胳蛮,更是在濱河造成了極大的恐慌销凑,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,270評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件仅炊,死亡現(xiàn)場離奇詭異斗幼,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)抚垄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,489評論 3 395
  • 文/潘曉璐 我一進(jìn)店門蜕窿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人呆馁,你說我怎么就攤上這事桐经。” “怎么了浙滤?”我有些...
    開封第一講書人閱讀 165,630評論 0 356
  • 文/不壞的土叔 我叫張陵阴挣,是天一觀的道長。 經(jīng)常有香客問我纺腊,道長屯吊,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,906評論 1 295
  • 正文 為了忘掉前任摹菠,我火速辦了婚禮,結(jié)果婚禮上骗爆,老公的妹妹穿的比我還像新娘次氨。我一直安慰自己,他們只是感情好摘投,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,928評論 6 392
  • 文/花漫 我一把揭開白布煮寡。 她就那樣靜靜地躺著,像睡著了一般犀呼。 火紅的嫁衣襯著肌膚如雪幸撕。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,718評論 1 305
  • 那天外臂,我揣著相機(jī)與錄音坐儿,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛貌矿,可吹牛的內(nèi)容都是我干的炭菌。 我是一名探鬼主播,決...
    沈念sama閱讀 40,442評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼逛漫,長吁一口氣:“原來是場噩夢啊……” “哼黑低!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起酌毡,我...
    開封第一講書人閱讀 39,345評論 0 276
  • 序言:老撾萬榮一對情侶失蹤克握,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后枷踏,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體菩暗,經(jīng)...
    沈念sama閱讀 45,802評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,984評論 3 337
  • 正文 我和宋清朗相戀三年呕寝,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了勋眯。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,117評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡下梢,死狀恐怖客蹋,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情孽江,我是刑警寧澤讶坯,帶...
    沈念sama閱讀 35,810評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站岗屏,受9級特大地震影響辆琅,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜这刷,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,462評論 3 331
  • 文/蒙蒙 一婉烟、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧暇屋,春花似錦似袁、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至定鸟,卻和暖如春而涉,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背联予。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評論 1 272
  • 我被黑心中介騙來泰國打工啼县, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留材原,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,377評論 3 373
  • 正文 我出身青樓谭羔,卻偏偏與公主長得像华糖,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子瘟裸,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,060評論 2 355

推薦閱讀更多精彩內(nèi)容

  • ¥關(guān)閉¥ 【雷霆戰(zhàn)機(jī)】 〖http://pan.baidu.com/s/1kVstszX〗 《解壓源碼后直接用AI...
    小菜c閱讀 9,452評論 0 19
  • ¥開啟¥ 【雷霆戰(zhàn)機(jī)】 〖http://pan.baidu.com/s/1kVstszX〗 《解壓源碼后直接用AI...
    小菜c閱讀 3,714評論 0 5
  • ¥開啟¥ 【雷霆戰(zhàn)機(jī)】 〖http://pan.baidu.com/s/1kVstszX〗 《解壓源碼后直接用AI...
    小菜c閱讀 3,547評論 1 10
  • ## 2015.06.05 - [開源利弊淺談 - 張超耀](移動(dòng)組周技術(shù)分享總結(jié)#開源利弊淺談---張超耀) -...
    XcodeYang閱讀 1,496評論 1 3
  • Objective-C是一個(gè)動(dòng)態(tài)語言客叉,有一個(gè)c和匯編語言編寫的runtime庫(lib.objc.A.dylib)...
    link_hui閱讀 230評論 0 0