forked from Jean13/others
-
Notifications
You must be signed in to change notification settings - Fork 0
/
carder.py
80 lines (59 loc) · 2.11 KB
/
carder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'''
Prints valid card numbers when supplied known prefix and suffix.
Both prefix and suffix are 4-digits each
For the algorithm used to validate card numbers, see:
https://en.wikipedia.org/wiki/Luhn_algorithm
'''
import itertools
import requests
import json
import string
# Verifies card
def digits_of(number):
return [int(i) for i in str(number)]
def luhn_checksum(card_number):
digits = digits_of(card_number)
odd_digits = digits[-1::-2]
even_digits = digits[-2::-2]
total = sum(odd_digits)
for digit in even_digits:
total += sum(digits_of(2 * digit))
return total % 10
def is_luhn_valid(card_number):
return luhn_checksum(card_number) == 0
# HTTP request - modify accordingly
url = "http://86dc35f7013f13cdb5a4e845a3d74937f2700c7b.ctf.site:20000/api.php"
data = {
"action":"start"
}
headers = {
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36",
"Content-Length":"18",
"Content-Type":"application/json",
"Host":"86dc35f7013f13cdb5a4e845a3d74937f2700c7b.ctf.site:20000",
"Origin":"http://86dc35f7013f13cdb5a4e845a3d74937f2700c7b.ctf.site:20000",
"Referer":"http://86dc35f7013f13cdb5a4e845a3d74937f2700c7b.ctf.site:20000/"
}
r = requests.get(url)
cookies = r.cookies
r = requests.post(url, data=json.dumps(data), cookies=cookies, headers=headers)
response = r.json()
cards = ['amex','visa','mcard']
# Length when 4-digit prefix and 4-dit suffix provided - modify accordingly
lengths = [7, 5, 8]
responseData = {}
for i in range(3):
start = response["p"+cards[i]]
ending = response["s"+cards[i]]
for s in itertools.product(string.digits, repeat=lengths[i]):
if(is_luhn_valid(start+''.join(s)+ending)):
print(cards[i])
print(len(start+''.join(s)+ending))
responseData["n"+cards[i]] = "".join(s)
break;
responseData["action"]="validate"
# Prints the valid values
print(json.dumps(responseData))
r = requests.post(url, data=json.dumps(responseData), cookies=cookies, headers=headers)
# Prints the response
print(r.text)