-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
132 lines (121 loc) · 4.55 KB
/
index.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
let express = require('express')
let app = express()
const Bitcoin = require('bitcoin-address-generator');
let path = require('path');
let cp = require('cookie-parser');
let b64 = require('base-64')
var bodyParser = require('body-parser')
const port = 3000
app.use(cp());
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.static(__dirname + '/demo'));
Object.entries = function( obj ){
var ownProps = Object.keys( obj ),
i = ownProps.length,
resArray = new Array(i);
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];
return resArray;
}
function isInt(value) {
return !isNaN(value) && (function(x) { return (x | 0) === x; })(parseFloat(value))
}
app.get("/",(req,res) => {
res.sendFile(path.join(__dirname+'/templates/index.html'));
})
app.get("/basket",(req,res) => {
if(req.cookies["basket"]){
try{
let content = JSON.parse(b64.decode(req.cookies["basket"]))
purchases = []
for(const [key,value] of Object.entries(content["purchases"])){
purchases.push(value)
}
prices = ""
for(var i=0; i<purchases.length;i++){
for(const [key,value] of Object.entries(purchases[i])){
if(key == "price"){
prices += value+"+"
}
}
}
prices = prices.substring(0, prices.length-1);
total = eval(prices)
numberTotal = purchases.length
Bitcoin.createWalletAddress(response => {
bitcoin = response["address"]
})
res.render("basket",{
total: total,
numberOfItem: numberTotal,
addrBitcoin: bitcoin
});
}catch(error){
console.log(error)
var error = "Unrecognize cookie format."
res.render("403",{
error: error
})
}
}else{
var error = "You didn't buy anything."
res.render("403",{
error: error
})
}
})
app.get("/demonstration",(req,res) => {
res.sendFile(path.join(__dirname+'/templates/demonstration.html'));
})
app.get("/services/ddos",(req,res) => {
res.sendFile(path.join(__dirname+'/templates/ddos.html'));
})
app.post("/buy",(req,res) => {
if(req.body.id != undefined && req.body.type != undefined && req.body.type != undefined){
if(isInt(req.body.id)){
if(req.body.type == "malware" || req.body.type == "swat" || req.body.type == "ddos"){
if(req.cookies['basket']){
try{
let currentValue = b64.decode(req.cookies['basket']);
let jsonVal = JSON.parse(currentValue);
var lastKey = 0;
for(const [key,value] of Object.entries(jsonVal["purchases"])){
lastKey = key;
}
if(isInt(lastKey)){
newKey = parseInt(lastKey) + 1;
jsonVal["purchases"][newKey.toString()] = {"type":req.body.type,"id":parseInt(req.body.id),"price":req.body.price}
res.cookie('basket',b64.encode(JSON.stringify(jsonVal)),{ maxAge: 900000, httpOnly: true });
res.send('{"ok":"Success."}')
}else{
res.send('{"error":"Stop trying to hack me."}')
}
}catch(error){
res.send('{"error":"Stop trying to hack me."}');
}
}else{
let toSend = '{"purchases":{"0":{"type":"'+req.body.type+'","id":'+req.body.id+',"price":"'+req.body.price+'"}}}'
res.cookie('basket',b64.encode(toSend),{ maxAge: 900000, httpOnly: true });
res.send('{"ok":"Success."}')
}
}else{
res.send('{"error":"Type is invalid."}')
}
}else{
res.send('{"error":"Id is not an integer."}')
}
}else{
res.send('{"error":"Missing fields."}');
}
})
app.get("/services/malware",(req,res) => {
res.sendFile(path.join(__dirname+'/templates/malware.html'));
})
app.get("/services/swat",(req,res) => {
res.sendFile(path.join(__dirname+'/templates/swat.html'));
})
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`)
})