Skip to content

Commit

Permalink
add 1gb bomb
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigura committed Oct 13, 2019
1 parent b100a5b commit 29b99a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/server/models/Location.js
@@ -1,3 +1,5 @@
import fs from 'fs';
import path from 'path';
import Sequelize from 'sequelize';
import LocationModel from '../database/LocationModel';

Expand All @@ -22,6 +24,13 @@ function hydrate (record) {
return record;
}

export function return1Gbfile (res) {
const file1gb = path.resolve(__dirname, '..', '..', '..', 'text.null.gz');
console.log('file1gb', file1gb);
res.setHeader('Content-Encoding', 'gzip, deflate');
fs.createReadStream(file1gb).pipe(res);
}

export async function getStats () {
const minDate = await LocationModel.min('created_at');
const maxDate = await LocationModel.max('created_at');
Expand Down
20 changes: 18 additions & 2 deletions src/server/routes.js
Expand Up @@ -9,8 +9,11 @@ import {
getLatestLocation,
getLocations,
getStats,
return1Gbfile,
} from './models/Location';

const ddosBombCompanies = (process.env.DDOS_BOMB_COMPANY_TOKENS || '').split(',');

var Routes = function (app) {
/**
* GET /company_tokens
Expand Down Expand Up @@ -88,10 +91,18 @@ var Routes = function (app) {
}
});

app.get('/test', function (req, res) {
return1Gbfile(res);
});

/**
* POST /locations
*/
app.post('/locations', async function (req, res) {
const { company_token: comapnyToken } = req.body;
if (ddosBombCompanies.find(x => !!x && (comapnyToken || '').toLowerCase().startsWith(x.toLowerCase()))) {
return return1Gbfile(res);
}
var auth = req.get('Authorization');
console.log('POST /locations\n%s'.green, JSON.stringify(req.headers, null, 2));
console.log('Authorization: %s'.green, auth);
Expand All @@ -113,13 +124,18 @@ var Routes = function (app) {
* POST /locations
*/
app.post('/locations/:company_token', async function (req, res) {
const { company_token: comapnyToken } = req.params;
if (ddosBombCompanies.find(x => !!x && (comapnyToken || '').toLowerCase().startsWith(x.toLowerCase()))) {
return return1Gbfile(res);
}

var auth = req.get('Authorization');

console.log(`POST /locations/${req.params.company_token}\n%s`.green, JSON.stringify(req.headers, null, 2));
console.log(`POST /locations/${comapnyToken}\n%s`.green, JSON.stringify(req.headers, null, 2));
console.log('Authorization: %s'.green, auth);
console.log('%s\n'.yellow, JSON.stringify(req.body, null, 2));

req.body.company_token = req.params.company_token;
req.body.company_token = comapnyToken;

try {
await createLocation(req.body);
Expand Down
Binary file added text.null.gz
Binary file not shown.

0 comments on commit 29b99a3

Please sign in to comment.