image.png

    原型污染就是指攻击者通过某种手段修改 JavaScript 对象的 prototype

    只有在下面3个条件同时满足时,漏洞利用才会发生:

    1. 对象递归合并
    2. 属性通过路径定义
    3. 对象克隆
    1. 'use strict';
    2. const express = require('express');
    3. const bodyParser = require('body-parser')
    4. const cookieParser = require('cookie-parser');
    5. const path = require('path');
    6. const isObject = obj => obj && obj.constructor && obj.constructor === Object;
    7. function merge(a, b) {
    8. for (var attr in b) {
    9. if (isObject(a[attr]) && isObject(b[attr])) {
    10. merge(a[attr], b[attr]);
    11. } else {
    12. a[attr] = b[attr];
    13. }
    14. }
    15. return a
    16. }
    17. function clone(a) {
    18. return merge({}, a);
    19. }
    20. // Constants
    21. const PORT = 8080;
    22. const HOST = '0.0.0.0';
    23. const admin = {};
    24. // App
    25. const app = express();
    26. app.use(bodyParser.json())
    27. app.use(cookieParser());
    28. app.use('/', express.static(path.join(__dirname, 'views')));
    29. app.post('/signup', (req, res) => {
    30. var body = JSON.parse(JSON.stringify(req.body));
    31. var copybody = clone(body)
    32. if (copybody.name) {
    33. res.cookie('name', copybody.name).json({
    34. "done": "cookie set"
    35. });
    36. } else {
    37. res.json({
    38. "error": "cookie not set"
    39. })
    40. }
    41. });
    42. app.get('/getFlag', (req, res) => {
    43. var аdmin = JSON.parse(JSON.stringify(req.cookies))
    44. if (admindmin == 1) {
    45. res.send("hackim19{}");
    46. } else {
    47. res.send("You are not authorized");
    48. }
    49. });
    50. app.listen(PORT, HOST);
    51. console.log(`Running on http://${HOST}:${PORT}`);

    image.png