language
stringclasses 10
values | tag
stringclasses 34
values | vulnerability_type
stringlengths 4
68
β | description
stringlengths 7
146
β | vulnerable_code
stringlengths 14
1.96k
| secure_code
stringlengths 18
3.21k
|
---|---|---|---|---|---|
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | SQL μ½μ
| SQL μ§μλ¬Έμ μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ§μλ¬Έμ΄ μ€νκ°λ₯ν
보μμ½μ | const mysql = require("mysql");
// 컀λ₯μ
μ΄κΈ°ν μ΅μ
μ μλ΅ν¨
const connection = mysql.createConnection(...);
router.get("/vuln/email", (req, res) => {
const con = connection;
const userInput = req.query.id;
// μ¬μ©μλ‘λΆν° μ
λ ₯λ°μ κ°μ κ²μ¦ μμ΄ κ·Έλλ‘ μΏΌλ¦¬μ μ¬μ©
const query = `SELECT email FROM user WHERE user_id = ${userInput}`;
con.query(query,
(err, result) => {
if (err) console.log(err);
return res.send(result);
}
);
}); | const mysql = require("mysql");
... router.get("/patched/email", (req, res) => {
const con = connection;
const userInput = req.query.id;
const query = βSELECT email FROM user WHERE user_id = ?β;
// 쿼리 ν¨μμ μ¬μ©μ μ
λ ₯κ°μ 맀κ°λ³μ ννλ‘ μ λ¬, μ΄λ κ² μμ±νλ©΄ μ¬μ©μ μ
λ ₯κ°μ
// escape μ²λ¦¬λ₯Ό ν κ²κ³Ό λμΌν κ²°κ³Όκ° μ€ν
con.query(query, userInput,
(err, result) => {
if (err) console.log(err);
return res.send(result);
}
);
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | SQL μ½μ
| SQL μ§μλ¬Έμ μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ§μλ¬Έμ΄ μ€νκ°λ₯ν
보μμ½μ | const mysql = require("mysql");
const Sequelize = require("sequelize");
const { QueryTypes } = require(βsequelizeβ);
// 컀λ₯μ
λ° ORM μ΄κΈ°ν μ΅μ
μ μλ΅ν¨
const connection = mysql.createConnection(...);
const sequelize = new Sequelize(...);
router.get("/vuln/orm/email", (req, res) => {
const userInput = req.query.id;
// μ¬μ©μλ‘λΆν° μ
λ ₯λ°μ κ°μ κ²μ¦ μμ΄ κ·Έλλ‘ μΏΌλ¦¬μ μ¬μ©
const query = `SELECT email FROM user WHERE user_id = ${userInput}`;
sequelize.query(query, { type: QueryTypes.SELECT })
.then((result) => {
return res.send(result);
}).catch((err) => {
console.log(err);
});
}); | router.get("/vuln/orm/email", (req, res) => {
const userInput = req.query.id;
// 쿼리 λ΄μμ λ°μΈλ©μ΄ νμν λΆλΆμ $numberλ‘ νκΈ°
const query = `SELECT email FROM user WHERE user_id = $1`;
// μΈμνλ 쿼리 κΈ°λ₯μ ν΅ν΄ 쿼리λ₯Ό μμ± λ° μ€ν
sequelize.query(query,
{
bind: [userInput],
type: QueryTypes.SELECT
})
.then((result) => {
return res.send(result);
}).catch((err) => {
console.log(err);
});
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ½λ μ½μ
| νλ‘μΈμ€κ° μΈλΆ μ
λ ₯κ°μ μ½λ(λͺ
λ Ήμ΄)λ‘ ν΄μΒ·μ€νν μ μκ³ νλ‘μΈμ€μ κ²μ¦λμ§ μμ μΈλΆ
μ
λ ₯κ°μ νμ©ν κ²½μ° μ
μμ μΈ μ½λκ° μ€ν κ°λ₯ν 보μμ½μ | const express = require('express');
router.post("/vuln/server", (req, res) => {
// μ¬μ©μλ‘λΆν° μ λ¬ λ°μ κ°μ κ·Έλλ‘ eval ν¨μμ μΈμλ‘ μ λ¬
const data = eval(req.body.data);
return res.send({ data });
}); | const express = require('express');
function alphanumeric(input_text) {
// μ κ·ννμ κΈ°λ° λ¬Έμμ΄ κ²μ¬
const letterNumber = /^[0-9a-zA-Z]+$/;
if (input_text.match(letterNumber)) {
return true;
} else {
return false;
}
}
router.post("/patched/server", (req, res) => {
let ret = null;
const { data } = req.body;
// μ¬μ©μ μ
λ ₯μ μλ¬Έ, μ«μλ‘ μ ννλ©°, λ§μ½ μ
λ ₯κ° λ΄μ νΉμλ¬Έμκ° ν¬ν¨λμ΄
// μμ κ²½μ° μλ¬ λ©μμ§λ₯Ό λ°ν
if (alphanumeric(data)) {
ret = eval(data);
} else {
ret = βerrorβ;
}
return res.send({ ret });
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | κ²½λ‘ μ‘°μ λ° μμ μ½μ
| μμ€ν
μμ μ κ·Όκ²½λ‘ λλ μμμ μ΄ λͺ
λ Ήμ΄μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μμ€ν
μμμ λ¬΄λ¨ μ κ·Ό λ° μ
μμ μΈ νμκ° κ°λ₯ν 보μμ½μ | const express = require('express');
const path = require('path');
router.get("/vuln/file", (req, res) => {
// μΈλΆ μ
λ ₯κ°μΌλ‘λΆν° νμΌλͺ
μ μ
λ ₯ λ°μ
const requestFile = req.query.file;
// μ
λ ₯κ°μ κ²μ¦ μμ΄ νμΌ μ²λ¦¬μ μ¬μ©
fs.readFile(path.resolve(__dirname, requestFile), 'utf8', function(err, data) {
if (err) {
return res.send('error');
}
return res.send(data);
})
}); | const express = require('express');
const path = require('path');
router.get("/patched/file", (req, res) => {
const requestFile = req.query.file;
// μ κ·ννμμ μ¬μ©ν΄ μ¬μ©μ μ
λ ₯κ°μ νν°λ§
const filtered = requestFile.replace(/[.\\\/]/gi, '');
fs.readFile(filtered, 'utf8', function(err, data) {
if (err) {
return res.send('error');
}
return res.send(data);
})
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | κ²½λ‘ μ‘°μ λ° μμ μ½μ
| μμ€ν
μμ μ κ·Όκ²½λ‘ λλ μμμ μ΄ λͺ
λ Ήμ΄μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μμ€ν
μμμ λ¬΄λ¨ μ κ·Ό λ° μ
μμ μΈ νμκ° κ°λ₯ν 보μμ½μ | const express = require('express');
const io = require("socket.io");
router.get("/vuln/socket", (req, res) => {
try {
// μΈλΆλ‘λΆν° μ
λ ₯λ°μ κ²μ¦λμ§ μμ μ£Όμλ₯Ό μ΄μ©νμ¬
// μμΌμ λ°μΈλ© νμ¬ μ¬μ©νκ³ μμ΄ μμ νμ§ μμ
const socket = io(req.query.url);
return res.send(socket);
} catch (err) {
return res.send("[error] fail to connect");
}
}); | const express = require('express');
const io = require("socket.io");
router.get("/patched/socket", (req, res) => {
// νμ΄νΈλ¦¬μ€νΈ λ΄μ μνλ μ£Όμλ§ νμ©
const whitelist = ["ws://localhost", "ws://127.0.0.1"];
if (whitelist.indexOf(req.query.url) < 0) {
return res.send("wrong url");
}
try {
const socket = io(req.query.url);
return res.send(socket);
} catch (err) {
return res.send("[error] fail to connect");
}
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μ€ν¬λ¦½νΈ(XSS) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ€ν¬λ¦½νΈκ° μ€ν κ°λ₯ν
보μμ½μ | <html>
<body>
<script>
const query = "<script>alert('hello world')<"+"/script>";
async function req() {
// μ¬μ©μκ° μλν°μ κ°μ μ
λ ₯ νΌμ μ
λ ₯ν λ°μ΄ν°λ₯Ό μλ²μ μ μ₯
const response = await fetch(`/vuln/search?q=${query}`, { method: 'GET' })
const data = await response.text();
// μΈλΆλ‘λΆν° λ°μ λ°μ΄ν°(HTML μ½λ)λ₯Ό μλ¬΄λ° κ²μ¦ μμ΄ DOMμΌλ‘ κΈ°λ‘
document.write(data);
}
req();
</script>
</body>
</html> | <html>
<body>
<script>
const query = "<script>alert('hello world')<"+"/script>";
async function req() {
const response = await fetch(`/vuln/search?q=${query}`, { method: 'GET' })
const data = await response.text();
// μΈλΆλ‘λΆν° λ°μ λ°μ΄ν°λ₯Ό μ΄μ€μΌμ΄ν μ²λ¦¬ ν μ¬μ©
document.write(decodeURI(encodeURIComponent(data)));
}
req();
</script>
</body>
</html> |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μ€ν¬λ¦½νΈ(XSS) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ€ν¬λ¦½νΈκ° μ€ν κ°λ₯ν
보μμ½μ | <html>
<body>
<script>
const query = "<script>alert('hello world')<"+"/script>";
async function req() {
// μ¬μ©μκ° μλν°μ κ°μ μ
λ ₯ νΌμ μ
λ ₯ν λ°μ΄ν°λ₯Ό μλ²μ μ μ₯
const response = await fetch(`/vuln/search?q=${query}`, { method: 'GET' })
const data = await response.text();
// μΈλΆλ‘λΆν° λ°μ λ°μ΄ν°(HTML μ½λ)λ₯Ό μλ¬΄λ° κ²μ¦ μμ΄ DOMμΌλ‘ κΈ°λ‘
document.write(data);
}
req();
</script>
</body>
</html> | <html>
<head>
<script src="https://cdn.rawgit.com/yahoo/xss-filters/master/dist/xss-filters.js"></script>
</head>
<body>
<script>
async function req() {
...
// xss-filters λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©ν΄ λ¬Έμμ΄μ μ΄μ€μΌμ΄ν μ²λ¦¬
document.write(xssFilters.inHTMLData(data));
}
req();
</script>
</body>
</html> |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μ€ν¬λ¦½νΈ(XSS) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ€ν¬λ¦½νΈκ° μ€ν κ°λ₯ν
보μμ½μ | function possibleXSS() {
return {
__html:
'<img
src="https://upload.wikimedia.org/wikipedia/commons/a/a7/React-icon.svgβ
onload="alert(1)">
</img>',
};
}
const App = ( ) => (
// XSSμ μ·¨μ½ν ν¨μλ₯Ό μ¬μ©ν΄ HTML μ½λ λ°μ΄ν°λ₯Ό λ λλ§
<div dangerouslySetInnerHTML={possibleXSS()} />
);
ReactDOM.render(<App />, document.getElementById("root")); | <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.4.0/purify.min.js"></script>
... function possibleXSS() {
return {
__html:
// dompurify λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©ν΄ μ
λ ₯κ°μ μ΄μ€μΌμ΄ν μ²λ¦¬
DOMPurify.sanitize('<img src="https://upload.wikimedia.org/wikipedia/commons/
a/a7/React-icon.svg" onload="alert(1)"></img>'),
};
}
const App = ( ) => (
<div dangerouslySetInnerHTML={possibleXSS()} />
);
ReactDOM.render(<App />, document.getElementById("root")); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μ€ν¬λ¦½νΈ(XSS) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ€ν¬λ¦½νΈκ° μ€ν κ°λ₯ν
보μμ½μ | const express = require('express');
router.get("/vuln/search", (req, res) => {
// μ¬μ©μλ‘λΆν° μ λ¬ λ°μ 쿼리 λ°μ΄ν°λ‘ λ°μ΄ν° μ‘°ν
const results = selectFromDB(req.query.q);
if (results.length === 0) {
// κ²μ κ²°κ³Όκ° λ°κ²¬λμ§ μμ κ²½μ°, βμμ²ν κ°βμ μ°Ύμ§ λͺ»νλ€λ λ©μμ§λ₯Ό λ°ννλλ°,
// μ΄ λ μ μμ μΈ μ§μλ¬Έμ΄ μλ μ
μ± μ€ν¬λ¦½νΈκ° ν¬ν¨λ λ°μ΄ν°λ₯Ό μ
λ ₯ λ°μ κ²½μ°λΌλ©΄
// ν΄λΌμ΄μΈνΈμΈ‘μμ μ
μ± μ€ν¬λ¦½νΈκ° μ€νλ μ μμ
return res.send('<p>No results found for "' + req.query.q + '"</p>');
} ... }); | const express = require('express');
const xssFilters = require("xss-filters");
... router.get("/patched/search", (req, res) => {
const unsafeFirstname = req.query.q;
// xss-filters λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©ν΄ μ¬μ©μ μ
λ ₯κ°μ μ΄μ€μΌμ΄ν μ²λ¦¬
const safeFirstname = xssFilters.inHTMLData(unsafeFirstname);
const results = selectFromDB(safeFirstname);
if (results.length === 0) {
res.send(util.format("<p>Hello %s</p>", safeFirstname));
}
... }); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ΄μ체μ λͺ
λ Ήμ΄ μ½μ
| μ΄μ체μ λͺ
λ Ήμ΄λ₯Ό μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ λͺ
λ Ήμ΄κ° μ€ν
κ°λ₯ν 보μμ½μ | const express = require('express');
const child_process = require("child_process");
router.get("/vuln", (req, res) => {
// μ¬μ©μκ° μ
λ ₯ν λͺ
λ Ήμ΄ μΈμκ°μ κ²μ¦ μμ΄ μ¬μ©ν΄ μλμΉ μμ μΆκ° λͺ
λ Ήμ΄ μ€ν κ°λ₯
child_process.exec("ls -l " + req.query.path, function (err, data) {
return res.send(data);
});
}); | const express = require('express');
const child_process = require("child_process");
router.get("/patched", (req, res) => {
const inputPath = req.query.path;
const regPath = /^(\/[\w^]+)+\/?$/;
// 첫 λ²μ§Έ λ°©λ², μ¬μ©μ μ
λ ₯κ° νν°λ§ ? 리λ
μ€ κ²½λ‘ μ§μ μ νμν λ¬Έμλ§ νμ©
if (!inputPath.match(regPath)) {
return res.send('not valid path');
}
// λ λ²μ§Έ λ°©λ², μ¬μ©μ μ
λ ₯κ°μ΄ λͺ
λ Ήμ΄μ μΈμλ‘λ§ μ¬μ©λλλ‘ νλ ν¨μ μ¬μ©
child_process.execFile(
"/bin/ls", ["-l", inputPath],
function (err, data) {
if (err) {
return res.send('not valid path');
} else {
return res.send(data);
}
}
);
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μνν νμ νμΌ μ
λ‘λ | νμΌμ νμ₯μ λ± νμΌνμμ λν κ²μ¦μμ΄ νμΌ μ
λ‘λλ₯Ό νμ©νμ¬ κ³΅κ²©μ΄ κ°λ₯ν 보μμ½μ | const express = require('express');
router.post("/vuln", (req, res) => {
const file = req.files.products;
const fileName = file.name;
// μ
λ‘λ ν νμΌ νμ
κ²μ¦ λΆμ¬λ‘ μ
μ± μ€ν¬λ¦½νΈ νμΌ μ
λ‘λ κ°λ₯
file.mv("/usr/app/temp/" + fileName, (err) => {
if (err) return res.send(err);
res.send("upload success");
});
}); | const express = require('express');
router.post("/patched", (req, res) => {
const allowedMimeTypes = ["image/png", "image/jpeg"];
const allowedSize = 5242880;
const file = req.files.products;
const fileName = file.name;
// μ
λ‘λ ν νμΌ νμ
κ²μ¦μ ν΅ν΄ μ
μ± μ€ν¬λ¦½νΈ νμΌ μ
λ‘λ λ°©μ§
if (allowedMimeTypes.indexOf(file.mimetype) < 0) {
res.send("file type not allowed");
} else {
file.mv("/usr/app/temp/" + fileName, (err) => {
if (err) return res.send(err);
res.send("upload success");
});
}
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ λ’°λμ§ μμ URLμ£Όμλ‘ μλμ μ μ°κ²° | URL λ§ν¬ μμ±μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ¬μ΄νΈλ‘ μλ μ μ κ°λ₯ν 보μμ½μ | const express = require('express');
router.get("/vuln", (req, res) => {
const url = req.query.url;
// μ¬μ©μκ° μ λ¬ν URL μ£Όμλ₯Ό κ²μ¦ μμ΄ κ·Έλλ‘ λ¦¬λ€μ΄λ νΈ μ²λ¦¬
res.redirect(url);
}); | const express = require('express');
router.get("/patched", (req, res) => {
const whitelist = ["http://safe-site.com", "https://www.example.com"];
const url = req.query.url;
// νμ΄νΈλ¦¬μ€νΈμ ν¬ν¨λ μ£Όμκ° μλλΌλ©΄ 리λ€μ΄λ νΈ μμ΄ μλ¬ λ°ν
if (whitelist.indexOf(url) < 0) {
res.send("wrong url");
} else {
res.redirect(url);
}
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | λΆμ μ ν XML μΈλΆ κ°μ²΄ μ°Έμ‘° | μμλ‘ μ‘°μλ XML μΈλΆκ°μ²΄μ λν μ μ ν κ²μ¦ μμ΄ μ°Έμ‘°λ₯Ό νμ©νμ¬ κ³΅κ²©μ΄ κ°λ₯ν 보μμ½μ | const express = require('express');
const libxmljs = require("libxmljs");
router.post("/vuln", (req, res) => {
if (req.files.products && req.files.products.mimetype == "application/xml") {
const products = libxmljs.parseXmlString(
req.files.products.data.toString("utf8"),
// μΈλΆ μν°ν° νμ± νμ© μ€μ (λ―Έμ€μ μ κΈ°λ³Έκ°μ false)
{ noent: true }
);
return res.send(products.get("//foo").text());
}
return res.send("fail");
}); | const express = require('express');
const libxmljs = require("libxmljs");
router.post("/patched", (req, res) => {
if (req.files.products && req.files.products.mimetype == "application/xml") {
const products = libxmljs.parseXmlString(
req.files.products.data.toString("utf8"),
// μΈλΆ μν°ν° νμ±μ νμ©νμ§ μλλ‘ μ€μ
// λ―Έμ€μ μ κΈ°λ³Έκ°μ falseμ΄μ§λ§, λͺ
μμ μΌλ‘ μ μΈμ ν΄ μ£Όλ κ²μ΄ μ’μ
{ noent: false }
);
return res.send(products.get("//foo").text());
}
return res.send("fail");
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | XML μ½μ
| XQuery, XPath μ§μλ¬Έμ μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ§μλ¬Έμ΄ μ€ν κ°λ₯ν 보μμ½μ | const express = require('express');
const xpath = require('xpath');
const dom = require('xmldom').DOMParser;
const xml = `<users>
<user>
<login>john</login>
<password>abracadabra</password>
<home_dir>/home/john</home_dir>
</user>
<user>
<login>cbc</login>
<password>1mgr8</password>
<home_dir>/home/cbc</home_dir>
</user>
</users>`;
router.get("/vuln", (req, res) => {
const userName = req.query.userName;
const userPass = req.query.userPass;
const doc = new dom().parseFromString(xml);
// μ‘°μλ μ
λ ₯κ°(/vuln?userName=john' or ''='&userPass="' or ''='β)μ ν΅ν΄
// ν¨μ€μλ κ²μ¬ λ‘μ§μ μ°νν μ μμ
const badXPathExpr = "//users/user[login/text()='" + userName
+ "' and password/text() = '" + userPass + "']/home_dir/text()";
const selected = xpath.select(badXPathExpr, doc);
try {
const userPath = selected[0].toString();
return res.send(`userPath = ${userPath}`);
} catch {
return res.send('not found');
}
}); | const express = require('express');
const xpath = require('xpath');
const dom = require('xmldom').DOMParser;
const xml = `<users>
...
</users>`;
router.get("/patched", (req, res) => {
const userName = req.query.userName;
const userPass = req.query.userPass;
const doc = new dom().parseFromString(xml);
// μΈμνλ 쿼리 μμ±
const goodXPathExpr = xpath.parse("//users/user[login/text()=$userName and password/text()
=$userPass]/home_dir/text()");
// 쿼리문μ λ³μκ° μ λ¬ λ° XML μ‘°ν
const selected = goodXPathExpr.select({
node: doc,
variables: { userName: userName, userPass: userPass }
});
try {
const userPath = selected[0].toString();
return res.send(`userPath = ${userPath}`);
} catch {
return res.send('not found');
}
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | LDAP μ½μ
| LDAP λͺ
λ Ήλ¬Έμ μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ λͺ
λ Ήμ΄κ° μ€ν κ°λ₯ν 보μμ½μ | const express = require('express');
const ldap = require('ldapjs');
const config = {
url: 'ldap://ldap.forumsys.com',
base: 'dc=example,dc=com',
dn: 'cn=read-only-admin,dc=example,dc=com',
secret: 'd0accf0ac0dfb0d0fd...',
};
async function searchLDAP (search) {
const opts = {
filter: `(&(objectClass=${search}))`,
attributes: ['sn', 'cn', 'mail', 'telephonenumber', 'uid'],
scope: 'sub',
};
const users = [];
const client = ldap.createClient({ url: config.url });
return new Promise((resolve, reject) => {
client.bind(config.dn, config.password, (err) => {
if (err) {
console.log('LDAP bind error - ', err);
} else {
client.search(config.base, opts, (err, res) => {
res.on('searchEntry', (entry) => {
users.push(entry.object);
});
...
res.on('end', (result) => {
console.log('status: ' + result.status);
resolve(users);
});
});
}
});
});
}
router.get("/vuln", async (req, res) => {
// μ¬μ©μμ μ
λ ₯μ κ·Έλλ‘ LDAP μ§μλ¬ΈμΌλ‘ μ¬μ©ν΄ κΆν μμΉ λ±μ 곡격μ λ
ΈμΆ
const search = req.query.search;
const result = await searchLDAP(search);
return res.send(result);
}); | const express = require('express');
const ldap = require('ldapjs');
const parseFilter = require('ldapjs').parseFilter;
const config = {
url: 'ldap://ldap.forumsys.com',
base: 'dc=example,dc=com',
dn: 'cn=read-only-admin,dc=example,dc=com',
secret: 'd0accf0ac0dfb0d0fd...',
};
async function searchLDAP (search) {
const opts = {
filter: `(&(objectClass=${search}))`,
attributes: ['sn', 'cn', 'mail', 'telephonenumber', 'uid'],
scope: 'sub',
};
const users = [];
const client = ldap.createClient({ url: config.url });
return new Promise((resolve, reject) => {
client.bind(config.dn, config.password, (err) => {
if (err) {
console.log('LDAP bind error - ', err);
} else {
client.search(config.base, opts, (err, res) => {
res.on('searchEntry', (entry) => {
users.push(entry.object);
});
...
res.on('end', (result) => {
console.log('status: ' + result.status);
resolve(users);
});
});
}
});
});
}
router.get("/patched", async (req, res) => {
let search;
// μ¬μ©μμ μ
λ ₯μ νν°λ§μ μ μ©ν΄ 곡격μ μ¬μ©λ μ μλ λ¬Έμ λ°κ²¬ μ
// μ¬μ©μμκ² μλͺ»λ μμ²κ°μμ μλ¦¬κ³ , μ§μλ¬Έμ μμ²νμ§ μμ
try {
search = parseFilter(req.query.search);
} catch {
return res.send('μλͺ»λ μμ²κ°μ
λλ€.');
}
const result = await searchLDAP(search);
return res.send(result);
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μμ² μμ‘°(CSRF) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ¬μ©μ λ³ΈμΈμ μμ§μλ 무κ΄νκ²
곡격μκ° μλν νμκ° μ€ν κ°λ₯ν 보μμ½μ | <html>
... <body>
<form method='post' action='/api/vuln'>
<!-- CSRF ν ν° μμ΄ νΌ λ°μ΄ν°λ₯Ό μλ²μ μ λ¬ -->
<fieldset>
<legend>Your Profile:</legend>
<label for='username'> Name:</label>
<input name='username' class='username' type='text'> <br><br>
<label for='email' > Email:</label>
<input name='email' class='useremail' type='email'> <br><br>
<button type='submit'>UPDATE</button>
</fieldset>
</form>
</body>
</html> | <form method='post' action='/api/vuln'>
<!-- μλ²λ‘λΆν° μ 곡 λ°μ CSRF ν ν°μ νΌ λ°μ΄ν°μ hidden κ°μΌλ‘ ν¬ν¨ν΄ μ λ¬ -->
<input type='hidden' name='_csrf' value='<%= csrfToken %>'>
<fieldset>
<legend>Your Profile:</legend>
<label for='username'> Name:</label>
<input name='username' class='username' type='text'> <br><br>
<label for='email' > Email:</label>
<input name='email' class='useremail' type='email'> <br><br>
<button type='submit'>UPDATE</button>
</fieldset>
</form> |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μμ² μμ‘°(CSRF) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ¬μ©μ λ³ΈμΈμ μμ§μλ 무κ΄νκ²
곡격μκ° μλν νμκ° μ€ν κ°λ₯ν 보μμ½μ | const express = require('express');
router.post("/api/vuln", (req, res) => {
const userName = req.body.username;
const userEmail = req.body.useremail;
// μ¬μ©μ μ
λ°μ΄νΈ μμ²μ΄ μ μ μ¬μ©μλ‘λΆν° μ¨ κ²μ΄λΌκ³ κ°μ£Όνκ³ ,
// μ¬μ©μλ‘λΆν° λ°μ κ°μ κ·Έλλ‘ λ΄λΆ ν¨μμ μ λ¬
if (update_user(userName, userEmail)) {
return res.send('update completed');
} else {
return res.send('update error');
}
}); | const csrf = require('csurf');
const express = require('express');
const session = require("express-session");
const app = express();
// ν ν°μ μΏ ν€κ° μλ μΈμ
μ μ μ₯
app.use(session({
secret: process.env.COOKIE_SECRET,
cookie: { path: '/', secure: true, httpOnly: true, sameSite: 'strict' },
saveUninitialized: false,
resave: false
}));
// CSRF ν ν° μ΄λ¦ μμ __Host- μ λμ΄ μΆκ°
const csrfProtection = csrf({
key: '__Host-token',
});
// ν΄λΌμ΄μΈνΈμΈ‘ νλ μμν¬(ReactJS)λ₯Ό μν ν ν° κ° μ 곡
router.get("/getCSRFToken", csrfProtection, (req, res) => {
res.json({ csrfToken: req.csrfToken() });
});
// ν
νλ¦Ώ νμ΄μ§λ₯Όμν ν ν° κ° μ 곡
router.get("/page", csrfProtection, (req, res) => {
res.render('csrf', { csrfToken: req.csrfToken() });
});
// λΌμ°ν° λ°μ΄ν° μ²λ¦¬ μ ν΄λΌμ΄μΈνΈμ csrf ν ν°μ κ²μ¬
router.post("/api/patched", csrfProtection, (req, res) => {
const userName = req.body.username;
const userEmail = req.body.useremail;
if (update_user(userName, userEmail)) {
return res.send('update completed');
} else {
return res.send('update error');
}
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μμ² μμ‘°(CSRF) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ¬μ©μ λ³ΈμΈμ μμ§μλ 무κ΄νκ²
곡격μκ° μλν νμκ° μ€ν κ°λ₯ν 보μμ½μ | ν΄λΌμ΄μΈνΈμΈ‘μμ λ λλ§μ μ²λ¦¬νλ ReactJSμ κ²½μ° μλ² κΈ°λ₯ νΈμΆ μ μλ²λ‘λΆν° ν ν°μ λ°μμ μμ² ν€λ
λ΄μ μ½μ
ν΄μΌ νλ€ | const App = () => {
const getData = async () => {
// μλ²μ κΈ°λ₯ νΈμΆ μ λ¨Όμ CSRF ν ν°μ λ°μμ ν€λμ μ μ₯
const response = await axios.get('getCSRFToken');
axios.defaults.headers.post['X-CSRF-Token'] = response.data.csrfToken;
// CSRF ν ν°μ΄ μ€μ λ μνμμ μλ² κΈ°λ₯ νΈμΆ
const res = await axios.post('api/patched', {
username: βhello_userβ,
useremail: β[email protected]β,
});
document.write(res.data);
};
React.useEffect(() => { getData(); }, []);
return <div>react-test</div>;
};
ReactDOM.render(<App />, document.getElementById("root")); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μλ²μ¬μ΄λ μμ² μμ‘° | μλ² κ° μ²λ¦¬λλ μμ²μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ κ³΅κ²©μκ° μλν μλ²λ‘ μ μ‘
νκ±°λ λ³μ‘°νλ 보μμ½μ | const request = require('request');
const express = require('express');
router.get("/vuln", async (req, res) => {
const url = req.query.url;
// μ¬μ©μκ° μ
λ ₯ν μ£Όμλ₯Ό κ²μ¦νμ§ μκ³ HTTP μμ²μ λ³΄λΈ ν
// κ·Έ μλ΅μ κ·Έλλ‘ μ¬μ©μμκ² μ λ¬
await request(url, (err, response) => {
const resData = response.body;
return res.send(resData);
});
}); | const request = require('request');
const express = require('express');
router.get("/patched", async (req, res) => {
const url = req.query.url;
const whiteList = [ 'www.example.com', 'www.safe.com'];
// μ¬μ©μκ° μ
λ ₯ν URLμ νμ΄νΈλ¦¬μ€νΈλ‘ κ²μ¦ν ν κ·Έ κ²°κ³Όλ₯Ό λ°ννμ¬
// κ²μ¦λμ§ μμ μ£Όμλ‘ μμ²μ 보λ΄μ§ μλλ‘ μ ν
if (whiteList.includes(url)) {
await request(url, (err, response) => {
const resData = response.body;
return res.send(resData);
});
} else {
return res.send('μλͺ»λ μμ²μ
λλ€');
}
}); |
Javascript | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | 보μκΈ°λ₯ κ²°μ μ μ¬μ©λλ λΆμ μ ν μ
λ ₯κ° | 보μκΈ°λ₯(μΈμ¦, κΆνλΆμ¬ λ±) κ²°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ λ³΄μκΈ°λ₯μ μ°ννλ
보μμ½μ | const express = require('express');
router.get("/admin", (req, res) => {
// μΏ ν€μμ κΆν μ 보λ₯Ό κ°μ Έμ΄
const role = req.cookies.role;
if (role === "admin") {
// μΏ ν€μμ κ°μ Έμ¨ κΆν μ λ³΄λ‘ κ΄λ¦¬μ νμ΄μ§ μ μ μ²λ¦¬
return res.render(βadminβ. { title: βκ΄λ¦¬μ νμ΄μ§β } ));
} else {
return res.send("μ¬μ© κΆνμ΄ μμ΅λλ€.");
}
}); | const express = require('express');
const session = require("express-session");
app.use(session({
secret: 'test',
resave: true,
saveUninitialized: true,
store: new MemoryStore({checkPeriod: 60 * 60 * 1000})
}));
router.get("/patched", (req, res) => {
// μΈμ
μμ κΆν μ 보λ₯Ό κ°μ Έμ΄
const role = req.session.role;
if (role === "admin") {
// μΈμ
μμ κ°μ Έμ¨ κΆν μ λ³΄λ‘ κ΄λ¦¬μ νμ΄μ§ μ μ μ²λ¦¬
return res.render(βadminβ. { title: βκ΄λ¦¬μ νμ΄μ§β } ));
} else {
return res.send("μ¬μ© κΆνμ΄ μμ΅λλ€.");
}
}); |
Javascript | 보μκΈ°λ₯ | μ μ ν μΈμ¦ μλ μ€μ κΈ°λ₯ νμ© | μ€μμ 보(κΈμ΅μ 보, κ°μΈμ 보, μΈμ¦μ 보 λ±)λ₯Ό μ μ ν μΈμ¦μμ΄ μ΄λ(λλ λ³κ²½) κ°λ₯ν
보μμ½μ | const express = require('express');
const crypto = require("crypto");
router.post("/vuln", (req, res) => {
const newPassword = req.body.newPassword;
const user = req.session.userid;
const hs = crypto.createHash(βsha256β)
const newHashPassword = hs.update(newPassword).digest("base64");
// νμ¬ ν¨μ€μλμ μΌμΉ μ¬λΆλ₯Ό νμΈνμ§ μκ³ μ
λ°μ΄νΈ
updatePasswordFromDB(user, newHashPassword);
return res.send({message: "ν¨μ€μλκ° λ³κ²½λμμ΅λλ€.", userId, password, hashPassword});
}); | const express = require('express');
const crypto = require("crypto");
router.post("/patched", (req, res) => {
const newPassword = req.body.newPassword;
const user = req.session.userid;
const oldPassword = getPasswordFromDB(user);
const salt = crypto.randomBytes(16).toString('hex');
const hs = crypto.createHash("sha256β)
const currentPassword = req.body.currentPassword;
const currentHashPassword = hs.update(currentPassword + salt).digest("base64");
// νμ¬ ν¨μ€μλ νμΈ ν μ¬μ©μ μ 보 μ
λ°μ΄νΈ
if (currentHashPassword === oldPassword) {
const newHashPassword = hs.update(newPassword + salt).digest("base64");
updatePasswordFromDB(user, newHashPassword);
return res.send({ message: "ν¨μ€μλκ° λ³κ²½λμμ΅λλ€." });
} else {
return res.send({ message: "ν¨μ€μλκ° μΌμΉνμ§ μμ΅λλ€." });
}
}); |
Javascript | 보μκΈ°λ₯ | λΆμ μ ν μΈκ° | μ€μμμμ μ κ·Όν λ μ μ ν μ μ΄κ° μμ΄ λΉμΈκ°μμ μ κ·Όμ΄ κ°λ₯ν 보μμ½μ | const express = require('express');
function deleteContentFromDB(contentId) {
... }
router.delete("/vuln", (req, res) => {
const contentId = req.body.contentId;
// μμ
μμ²μ νλ μ¬μ©μμ κΆν νμΈ μμ΄ μμ μμ
μν
deleteContentFromDB(contentId);
return res.send("μμ κ° μλ£λμμ΅λλ€.");
}); | const express = require('express');
function deleteContentFromDB(contentId) { ... }
router.delete("/patched", (req, res) => {
const contentId = req.body.contentId;
const role = req.session.role;
// μμ κΈ°λ₯μ μνν κΆνμ΄ μλ κ²½μ°μλ§ μμ μμ
μν
if (role === "admin") {
deleteContentFromDB(contentId);
return res.send("μμ κ° μλ£λμμ΅λλ€.");
} else {
return res.send("κΆνμ΄ μμ΅λλ€.");
}
}); |
Javascript | 보μκΈ°λ₯ | μ€μν μμμ λν μλͺ»λ κΆν μ€μ | μ€μμμμ μ μ ν μ κ·Ό κΆνμ λΆμ¬νμ§ μμ μ€μμ λ³΄κ° λ
ΈμΆΒ·μμ κ°λ₯ν 보μμ½μ | const fs = require("fs");
function writeFile() {
// λͺ¨λ μ¬μ©μκ° μ½κΈ°, μ°κΈ°, μ€ν κΆνμ κ°μ§κ² λ¨
fs.chmodSync("/root/system_config", 0o777);
fs.open("/root/system_config", "w", function(err,fd) {
if (err) throw err;
});
fs.writeFile("/root/system_config", "your config is broken", function(err) {
if (err) throw err;
console.log('write end');
});
} | const fs = require("fs");
function writeFile() {
// μμ μ μ΄μΈμλ κΆνμ κ°μ§μ§ μμ
fs.chmodSync("/root/system_config", 0o700);
fs.open("/root/system_config", "w", function(err,fd) {
if (err) throw err;
});
fs.writeFile("/root/system_config", "your config is broken", function(err) {
if (err) throw err;
console.log('write end');
})
} |
Javascript | 보μκΈ°λ₯ | μ·¨μ½ν μνΈν μκ³ λ¦¬μ¦ μ¬μ© | μ€μμ 보 (κΈμ΅μ 보, κ°μΈμ 보, μΈμ¦μ 보 λ±)μ κΈ°λ°μ±μ 보μ₯ν μ μλ μ·¨μ½ν μνΈν μ
κ³ λ¦¬μ¦μ μ¬μ©νμ¬ μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | const crypto = require("crypto");
function getEncText(plainText, key) {
// μ·¨μ½ν μκ³ λ¦¬μ¦μΈ DESλ₯Ό μ¬μ©νμ¬ μμ νμ§ μμ
const cipherDes = crypto.createCipheriv('des-ecb', key, '');
const encryptedData = cipherDes.update(plainText, 'utf8', 'base64');
const finalEnctypedData = cipherDes.final('base64');
return encryptedData + finalEnctypedData;
} | const crypto = require("crypto");
function getEncText(plainText, key, iv) {
// κΆμ₯ μκ³ λ¦¬μ¦μΈ AESλ₯Ό μ¬μ©νμ¬ μμ ν¨
const cipherAes = crypto.createCipheriv('aes-256-cbc', key, iv);
const encryptedData = cipherAes.update(plainText, 'utf8', 'base64');
const finalEnctypedData = cipherAes.final('base64');
return encryptedData + finalEnctypedData;
} |
Javascript | 보μκΈ°λ₯ | μ·¨μ½ν μνΈν μκ³ λ¦¬μ¦ μ¬μ© | μ€μμ 보 (κΈμ΅μ 보, κ°μΈμ 보, μΈμ¦μ 보 λ±)μ κΈ°λ°μ±μ 보μ₯ν μ μλ μ·¨μ½ν μνΈν μ
κ³ λ¦¬μ¦μ μ¬μ©νμ¬ μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | const crypto = require("crypto");
function makeMd5(plainText) {
// μ·¨μ½ν md5 ν΄μ¬ν¨μ μ¬μ©
const hashText = crypto.createHash('md5').update(plainText).digest("hex");
return hashText;
} | const crypto = require("crypto");
function makeSha256(plainText) {
const salt = crypto.randomBytes(16).toString('hex');
// μμ ν sha-256 ν΄μ¬ν¨μ μ¬μ©
const hashText = crypto.createHash('sha256').update(plainText + salt).digest("hex");
return hashText;
} |
Javascript | 보μκΈ°λ₯ | μνΈνλμ§ μμ μ€μμ 보 | μ€μμ 보(ν¨μ€μλ, κ°μΈμ 보 λ±) μ μ‘ μ μνΈν λλ μμ ν ν΅μ μ±λμ μ΄μ©νμ§ μκ±°λ, μ μ₯ μ μνΈν νμ§ μμ μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | function updatePass(dbconn, password, user_id) {
// μνΈνλμ§ μμ λΉλ°λ²νΈλ₯Ό DBμ μ μ₯νλ κ²½μ° μνν¨
const sql = 'UPDATE user SET password=? WHERE user_id=?';
const params = [password, user_id];
dbconn.query(sql, params, function(err, rows, fields){
if (err) console.log(err);
})
} | const crypto = require("crypto");
function updatePass(dbconn, password, user_id, salt) {
// λ¨λ°©ν₯ μνΈνλ₯Ό μ΄μ©νμ¬ λΉλ°λ²νΈλ₯Ό μνΈν
const sql = 'UPDATE user SET password=? WHERE user_id=?';
const hashPw = crypto.createHash('sha256').update(password + salt, 'utf-8').digest('hex');
const params = [hashPw, user_id];
dbconn.query(sql, params, function(err, rows, fields){
if (err) console.log(err);
})
} |
Javascript | 보μκΈ°λ₯ | μνΈνλμ§ μμ μ€μμ 보 | μ€μμ 보(ν¨μ€μλ, κ°μΈμ 보 λ±) μ μ‘ μ μνΈν λλ μμ ν ν΅μ μ±λμ μ΄μ©νμ§ μκ±°λ, μ μ₯ μ μνΈν νμ§ μμ μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | const { io } = require("socket.io-client");
const socket = io("http://localhost:3000");
function sendPassword(password) {
// ν¨μ€μλλ₯Ό μνΈν νμ§ μκ³ μ μ‘νμ¬ μμ νμ§ μμ
socket.emit("password", password);
}
socket.on("password", function(data) {
if (data === 'success') {
console.log("\nSuccess to send a message to a server \n")
}
}); | const { io } = require("socket.io-client");
const crypto = require("crypto");
const socket = io("http://localhost:3000");
const PASSWORD = getPassword();
function aesEncrypt(plainText) {
const key = getCryptKey();
const iv = getCryptIV();
const cipherAes = crypto.createCipheriv('aes-256-cbc', key, iv);
const encryptedData = cipherAes.update(plainText, 'utf8', 'base64');
const finalEncryptedData = cipherAes.final('base64');
return encryptedData + finalEncryptedData;
}
function sendPassword(password) {
// ν¨μ€μλ λ± μ€μμ 보λ μνΈννμ¬ μ μ‘νλ κ²μ΄ μμ ν¨
const encPassword = aesEncrypt(password);
socket.emit("password", encPassword);
}
socket.on("password", function(data) {
if (data === 'success') {
console.log("\nSuccess to send a message to a server \n")
}
}); |
Javascript | 보μκΈ°λ₯ | νλμ½λλ μ€μμ 보 | μμ€μ½λμ μ€μμ 보(ν¨μ€μλ, μνΈνν€ λ±)λ₯Ό μ§μ μ½λ©νμ¬ μμ€μ½λ μ μΆ μ μ€μμ λ³΄κ° λ
ΈμΆλκ³ μ£ΌκΈ°μ λ³κ²½μ΄ μ΄λ €μ΄ 보μμ½μ | const express = require('express');
const mysql = require("mysql");
const crypto = require("crypto");
const dbQuery = "SELECT email, name FROM user WHERE name = 'test'";
router.get("/vuln", (req, res) => {
// λ°μ΄ν°λ² μ΄μ€ μ°κ²°μ νμν μΈμ¦ μ λ³΄κ° νλ¬ΈμΌλ‘ νλμ½λ©λμ΄ μμ
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root1234',
database: 'javascript',
port: 3306,
});
connection.query(
dbQuery, (err, result) => {
if (err) return res.send(err);
return res.send(result);
})
}); | const express = require('express');
const mysql = require("mysql");
const crypto = require("crypto");
const dbQuery = "SELECT email, name FROM user WHERE name = 'test'";
const key = getCryptKey(); // 32bytes
const iv = getCryptIV(); // 16bytes
router.get("/patched", (req, res) => {
// μ€μ νμΌμ μνΈν λμ΄ μλ user, password μ 보λ₯Ό κ°μ Έμ 볡νΈν ν ν μ¬μ©
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
const user = decipher.update(process.env.USER, 'base64', 'utf8') + decipher.final('utf8');
const decipher2 = crypto.createDecipheriv('aes-256-cbc', key, iv);
const password = decipher2.update(process.env.PASSWORD, 'base64', 'utf8') + decipher2.final
('utf8');
// DB μ°κ²° μ 보λ μ€μ νμΌμμ κ°μ Έμ μ¬μ©
const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: user,
password: password,
database: process.env.DB_NAME,
port: process.env.PORT,
}); |
Javascript | 보μκΈ°λ₯ | μΆ©λΆνμ§ μμ ν€ κΈΈμ΄ μ¬μ© | μνΈν λ±μ μ¬μ©λλ ν€μ κΈΈμ΄κ° μΆ©λΆνμ§ μμ λ°μ΄ν°μ κΈ°λ°μ±Β·λ¬΄κ²°μ±μ 보μ₯ν μ μλ 보μμ½μ | const crypto = require("crypto");
function vulnMakeRsaKeyPair() {
// RSAν€ κΈΈμ΄λ₯Ό 1024 λΉνΈλ‘ μ€μ νλ κ²½μ° μμ νμ§ μμ
const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa',
{
modulusLength: 1024,
publicKeyEncoding: { type: "spki", format: 'pem' },
privateKeyEncoding: { type: "pkcs8", format: 'pem' }
});
return { PRIVATE: publicKey, PUBLIC: privateKey }
}
function vulnMakeEcc() {
// ECC ν€ κΈΈμ΄κ° 224λΉνΈ μ΄νμ΄λ©΄ μμ νμ§ μμ
const { publicKey, privateKey } = crypto.generateKeyPairSync('ec', {
namedCurve: 'secp192k1',
publicKeyEncoding: { type: 'spki', format: 'der' },
privateKeyEncoding: { type: 'pkcs8', format: 'der' }
});
return { PRIVATE: publicKey.toString('hex'), PUBLIC: privateKey.toString('hex') }
} | const crypto = require("crypto");
function vulnMakeRsaKeyPair() {
// RSAν€ κΈΈμ΄λ₯Ό 2048 λΉνΈλ‘ μ€μ ν΄ μμ ν¨
const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa',
{
modulusLength: 2048,
publicKeyEncoding: { type: "spki", format: 'pem' },
privateKeyEncoding: { type: "pkcs8", format: 'pem' }
});
return { PRIVATE: publicKey, PUBLIC: privateKey }
}
function vulnMakeEcc() {
// ECC ν€ κΈΈμ΄λ₯Ό 256 λΉνΈλ‘ μ€μ ν΄ μμ ν¨
const { publicKey, privateKey } = crypto.generateKeyPairSync('ec', {
namedCurve: 'secp256k1',
publicKeyEncoding: { type: 'spki', format: 'der' },
privateKeyEncoding: { type: 'pkcs8', format: 'der' }
});
return { PRIVATE: publicKey.toString('hex'), PUBLIC: privateKey.toString('hex') }
} |
Javascript | 보μκΈ°λ₯ | μ μ νμ§ μμ λμ κ° μ¬μ© | μ¬μ©ν λμκ° μμΈ‘ κ°λ₯νμ¬, 곡격μκ° λ€μ λμλ₯Ό μμν΄μ μμ€ν
μ 곡격 κ°λ₯ν 보μ
μ½μ | function getOtpNumber() {
let randomStr = '';
// Math.random λΌμ΄λΈλ¬λ¦¬λ 보μκΈ°λ₯μ μ¬μ©νλ©΄ μνν¨
for (let i = 0; i < 6; i++) {
randomStr += String(Math.floor(Math.random() * 10))
}
return randomStr;
} | const crypto = require("crypto");
function getOtpNumber() {
// 보μκΈ°λ₯μ μ ν©ν λμ μμ±μ© crypto λΌμ΄λΈλ¬λ¦¬ μ¬μ©
const array = new Uint32Array(1);
// λΈλΌμ°μ μμλ crypto λμ μ window.cryptoλ₯Ό μ¬μ©
const randomStr = crypto.getRandomValues(array);
let result;
for (let i = 0; i < randomStr.length; i++) {
result = array[i];
}
return String(result).substring(0, 6);
} |
Javascript | 보μκΈ°λ₯ | μ·¨μ½ν ν¨μ€μλ νμ© | ν¨μ€μλ μ‘°ν©κ·μΉ(μλ¬Έ, μ«μ, νΉμλ¬Έμ λ±) λ―Έν‘ λ° κΈΈμ΄κ° μΆ©λΆνμ§ μμ ν¨μ€μλκ°
λ
ΈμΆ κ°λ₯ν 보μμ½μ | const express = require('express');
const mysql = require("mysql");
const connection = mysql.createConnection( ... );
router.post("/vuln", (req, res) => {
const con = connection;
const { email, password, name } = req.body;
// ν¨μ€μλ μμ± κ·μΉ κ²μ¦ μμ΄ νμ κ°μ
μ²λ¦¬
con.query(
"INSERT INTO user (email, password, name) VALUES (?, ?, ?)",
[email, password, name],
(err, result) => {
if (err) return res.send(err);
return res.send("νμκ°μ
μ±κ³΅");
});
}); | const express = require('express');
const mysql = require("mysql");
const connection = mysql.createConnection(...);
router.post("/patched", (req, res) => {
const con = connection;
const { email, password, name } = req.body;
function checkPassword(password) {
// 2μ’
μ΄μ λ¬Έμλ‘ κ΅¬μ±λ 8μ리 μ΄μ λΉλ°λ²νΈ κ²μ¬ μ κ·μ
const pt1 = /^(?=.*[A-Z])(?=.*[a-z])[A-Za-z\d!@#$%^&*]{8,}$/;
const pt2 = /^(?=.*[A-Z])(?=.*\d)[A-Za-z\d!@#$%^&*]{8,}$/;
const pt3 = /^(?=.*[A-Z])(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$/;
const pt4 = /^(?=.*[a-z])(?=.*\d)[A-Za-z\d!@#$%^&*]{8,}$/;
const pt5 = /^(?=.*[a-z])(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$/;
const pt6 = /^(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$/;
// λ¬Έμ κ΅¬μ± μκ΄μμ΄ 10μ리 μ΄μ λΉλ°λ²νΈ κ²μ¬ μ κ·μ
const pt7 = /^[A-Za-z\d!@#$%^&*]{10,}$/;
for (let pt of [pt1, pt2, pt3, pt4, pt5, pt6, pt7]) {
console.log(pt.test(password));
if (pt.test(password)) return true;
}
return false;
}
if (checkPassword(password)) {
con.query(
"INSERT INTO user (email, password, name) VALUES (?, ?, ?)",
[email, password, name],
(err, result) => {
if (err) return res.send(err);
return res.send("νμκ°μ
μ±κ³΅");
}
);
} else {
return res.send("λΉλ°λ²νΈλ μλ¬Έ λλ¬Έμ, μλ¬Έμ, μ«μ, νΉμλ¬Έμ μ‘°ν© μ€ 2κ°μ§ μ΄μ 8μ리μ΄κ±°λ
λ¬Έμ κ΅¬μ± μκ΄μμ΄ 10μ리 μ΄μμ΄μ΄μΌ ν©λλ€.");
}
}); |
Javascript | 보μκΈ°λ₯ | λΆμ μ ν μ μμλͺ
νμΈ | νλ‘κ·Έλ¨, λΌμ΄λΈλ¬λ¦¬, μ½λμ μ μμλͺ
μ λν μ ν¨μ± κ²μ¦μ΄ μ μ νμ§ μμ 곡격μμ
μ
μμ μΈ μ½λκ° μ€ν κ°λ₯ν 보μμ½μ | const express = require('express');
const crypto = require("crypto");
const fs = require(βfsβ);
router.post("/vuln", (req, res) => {
// ν΄λΌμ΄μΈνΈλ‘λΆν° μ λ¬λ°μ λ°μ΄ν°(μ μμλͺ
μ μμ μ²λ¦¬ νμ§ μμ)
const { encrypted_msg } = req.body;
let secret_key;
fs.readFile(β/keys/secret_key.outβ, βutf8β, (err, data) => {
if (err) {
console.error(err);
return;
}
secret_key = data;
}
// λμΉν€λ‘ ν΄λΌμ΄μΈνΈκ° μ λ¬ν μ½λ 볡νΈν
// (decrypt_with_symmetric_key ν¨μλ μμμ ν¨μλͺ
μΌλ‘ μΈλΆμ μΈ λ³΅νΈν κ³Όμ μ μλ΅ν¨)
const decrypted = decrypt_with_symmetric_key(encrypted_msg, secret_key);
// ν΄λΌμ΄μΈνΈλ‘λΆν° μ λ¬ λ°μ μ½λ μ€ν
eval(decrypted);
res.send('μμ²ν μ½λλ₯Ό μ€ννμ΅λλ€');
}); | // μ μμλͺ
κ²μ¦μ μ¬μ©ν μ½λλ μμ‘΄ν ν¨ν€μ§ λ° μ‘μ μΈ‘ μΈμ΄μ λ°λΌ
// λ¬λΌμ§ μ μμΌλ©°, μλͺ
μ μ 곡ν μλ²μ 곡κ°ν€λ‘ 볡νΈνν μ μμλͺ
κ³Ό μλ³Έ λ°μ΄ν° ν΄μ¬κ°μ
// μΌμΉ μ¬λΆλ₯Ό κ²μ¬νλ μ½λλ₯Ό ν¬ν¨
const express = require('express');
const crypto = require("crypto");
router.post("/patched", (req, res) => {
const { encrypted_msg, encrypted_sig, client_pub_key } = req.body;
let secret_key;
fs.readFile(β/keys/secret_key.outβ, βutf8β, (err, data) => {
if (err) {
console.error(err);
return;
}
secret_key = data;
}
// λμΉν€λ‘ ν΄λΌμ΄μΈνΈ λ°μ΄ν° λ° μ μμλͺ
볡νΈν
const decrypted_msg = decrypt_with_symmetric_key(encrypted_msg);
const decrypted_sig = decrypt_with_symmetric_key(encrypted_sig);
// μ μμλͺ
κ²μ¦μ ν΅κ³Όν κ²½μ°μλ§ λ°μ΄ν° μ€ν
if (verify_digit_signature(decrypted_msg, decrypted_sig, clint_pub_key)) {
eval(decrypted_msg);
res.send('μμ²ν μ½λλ₯Ό μ€ννμ΅λλ€');
} else {
res.send('[!] μλ¬ - μλͺ
μ΄ μ¬λ°λ₯΄μ§ μμ΅λλ€.');
}
}); |
Javascript | 보μκΈ°λ₯ | λΆμ μ ν μΈμ¦μ
μ ν¨μ± κ²μ¦ | μΈμ¦μμ λν μ ν¨μ± κ²μ¦μ΄ μ μ νμ§ μμ λ°μνλ 보μμ½μ | const https = require('https');
const getServer = () => {
const options = {
hostname: "dangerous.website",
port: 443,
method: "GET",
path: "/",
// μ ν¨νμ§ μμ μΈμ¦μλ₯Ό κ°μ§κ³ μμ΄λ 무μνλ μ΅μ
μΌλ‘ μμ νμ§ μμ
rejectUnauthorized: false
};
https.request(
options, (response) => {
console.log('response - ', response.statusCode);
}
);
}); | const express = require('express');
const https = require('https');
const getServer = () => {
const options = {
hostname: "dangerous.website",
port: 443,
method: "GET",
path: "/",
// μ ν¨νμ§ μμ μΈμ¦μ λ°κ²¬ μ μμΈ λ°μ
rejectUnauthorized: true
};
const hreq = https.request(
options, (response) => {
console.log('response - ', response.statusCode);
}
);
hreq.on('error', (e) => {
console.error('μλ¬λ°μ - ', e);
});
}); |
Javascript | 보μκΈ°λ₯ | μ¬μ©μ νλλμ€ν¬μ μ μ₯λλ μΏ ν€λ₯Ό ν΅ν μ 보λ
ΈμΆ | μΏ ν€(μΈμ
ID, μ¬μ©μ κΆνμ 보 λ± μ€μμ 보)λ₯Ό μ¬μ©μ νλλμ€ν¬μ μ μ₯νμ¬ μ€μμ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | const express = require('express');
router.get("/vuln", (req, res) => {
// μΏ ν€μ λ§λ£ μκ°μ 1λ
μΌλ‘ κ³Όλνκ² κΈΈκ² μ€μ νκ³ μμ΄ μμ νμ§ μλ€
res.cookie('rememberme', '1', {
expires: new Date(Date.now() + 365*24*60*60*1000)
});
return res.send("μΏ ν€ λ°κΈ μλ£");
}); | const express = require('express');
router.get("/patched", (req, res) => {
// μΏ ν€μ λ§λ£ μκ°μ μ μ νκ² λΆμ¬νκ³ secure μ΅μ
μ νμ±ν
res.cookie('rememberme', '1', {
expires: new Date(Date.now() + 60*60*1000),
secure: true,
httpOnly: true
});
return res.send("μΏ ν€ λ°κΈ μλ£");
}); |
Javascript | 보μκΈ°λ₯ | μ£Όμλ¬Έ μμ ν¬ν¨λ
μμ€ν
μ£Όμμ 보 | μμ€μ½λ μ£Όμλ¬Έμ μΈμ¦μ 보 λ± μμ€ν
μ£Όμμ λ³΄κ° ν¬ν¨λμ΄ μμ€μ½λ λ
ΈμΆ μ μ£Όμμ 보λ λ
ΈμΆ κ°λ₯ν 보μμ½μ | const express = require('express');
router.post("/vuln", (req, res) => {
// μ£Όμλ¬Έμ ν¬ν¨λ μ€μ μμ€ν
μ μΈμ¦ μ 보
// id = admin
// password = 1234
const result = login(req.body.id, req.body.password);
return res.send(result);
}); | const express = require('express');
router.post("/vuln", (req, res) => {
// μ£Όμλ¬Έμ ν¬ν¨λ λ―Όκ°ν μ 보λ μμ
const result = login(req.body.id, req.body.password);
return res.send(result);
}); |
Javascript | 보μκΈ°λ₯ | μνΈ μμ΄ μΌλ°©ν₯
ν΄μ¬ ν¨μ μ¬μ© | μνΈλ₯Ό μ¬μ©νμ§ μκ³ μμ±λ ν΄μ¬ κ°μΌλ‘λΆν° 곡격μκ° λ―Έλ¦¬ κ³μ°λ λ μΈλ³΄μ° ν
μ΄λΈμ
μ΄μ©νμ¬ ν΄μ¬ μ μ© μ΄μ μλ³Έ μ 보λ₯Ό 볡μκ°λ₯ν 보μμ½μ | const crypto = require("crypto");
function getHashFromPwd(pw) {
// saltκ° μμ΄ μμ±λ ν΄μ¬κ°μ κ°λκ° μ½ν΄ μ·¨μ½
const hash = crypto.createHash('sha256').update(pw).digest('hex');
return hash;
} | const crypto = require("crypto");
function getHashFromPwd(pw) {
// μνΈ κ°μ μ¬μ©νλ©΄ κΈΈμ΄κ° 짧μ ν¨μ€μλλ‘λ κ³ κ°λμ ν΄μ¬λ₯Ό μμ±ν μ μμ
// μνΈ κ°μ μ¬μ©μλ³λ‘ μ μΌνκ² μμ±ν΄μΌ νλ©°, ν¨μ€μλμ ν¨κ» DBμ μ μ₯ν΄μΌ ν¨
const salt = crypto.randomBytes(16).toString('hex');
const hash = crypto.createHash('sha256').update(pw + salt).digest('hex');
return { hash, salt };
} |
Javascript | 보μκΈ°λ₯ | λ¬΄κ²°μ± κ²μ¬ μλ μ½λ
λ€μ΄λ‘λ | μμ€μ½λ λλ μ€ννμΌμ λ¬΄κ²°μ± κ²μ¬ μμ΄ λ€μ΄λ‘λ λ°μ μ€ννλ κ²½μ°, 곡격μμ μ
μ
μ μΈ μ½λκ° μ€ν κ°λ₯ν 보μμ½μ | const express = require('express');
const fs = require("fs");
const http = require("http");
router.get("/vuln", (req, res) => {
// μ λ’°ν μ μλ μ¬μ΄νΈμμ μ½λλ₯Ό λ€μ΄λ‘λ
const url = "https://www.somewhere.com/storage/code.js";
// μ격 μ½λ λ€μ΄λ‘λ
http.get(url, (res) => {
const path = "./temp/sample1.js"
const writeStream = fs.createWriteStream(path);
res.pipe(writeStream);
writeStream.on("finish", () => {
writeStream.close();
});
});
// λ¬΄κ²°μ± κ²μ¦ μμ΄ νμΌ μ¬μ©
fs.readFile("./temp/sample1.js", "utf8", function (err, buf) {
res.end(buf);
})
}); | const express = require('express');
const fs = require("fs");
const http = require("http");
const crypto = require("crypto");
router.get("/patched", async (req, res) => {
const url = "https://www.somewhere.com/storage/code.js";
const codeHash = req.body.codeHash;
http.get(url, (res) => {
const path = "./temp/sample1.js"
const writeStream = fs.createWriteStream(path);
res.pipe(writeStream);
writeStream.on("finish", () => {
writeStream.close();
});
});
const hash = crypto.createHash('sha256');
const input = fs.createReadStream("./temp/sample1.js");
let promise = new Promise ((resolve, reject) => {
input.on("readable", () => {
const data = input.read();
if (data) { hash.update(data); }
else { resolve(); }
})
});
await promise;
const fileHash = hash.digest('hex');
# λ¬΄κ²°μ± κ²μ¦μ ν΅κ³Όν κ²½μ°μλ§ νμΌ μ¬μ©
if (fileHash === codeHash) {
fs.readFile("./temp/sample1.js", "utf8", function (err, buf) {
res.end(buf);
})
} else {
return res.send("νμΌμ΄ μμλμμ΅λλ€.")
}
}); |
Javascript | 보μκΈ°λ₯ | λ°λ³΅λ μΈμ¦μλ
μ ν κΈ°λ₯ λΆμ¬ | μΈμ¦ μλ μλ₯Ό μ ννμ§ μμ 곡격μκ° λ°λ³΅μ μΌλ‘ μμ κ°μ μ
λ ₯νμ¬ κ³μ κΆνμ νλ
κ°λ₯ν 보μμ½μ | const express = require('express');
const crypto = require('crypto');
router.post("/vuln", (req, res) => {
const id = req.body.id;
const password = req.body.password;
const hashPassword = crypto.createHash("sha512").update(password).digest("base64");
const currentHashPassword = getUserPasswordFromDB(id);
// μΈμ¦ μλμ λ°λ₯Έ μ νμ΄ μμ΄ λ°λ³΅μ μΈ μΈμ¦ μλκ° κ°λ₯
if (hashPassword === currentHashPassword) {
return res.send("login success");
} else {
return res.send("login fail")
}
}); | const express = require('express');
const crypto = require('crypto');
const LOGIN_TRY_LIMIT = 5;
router.post("/patched", (req, res) => {
const id = req.body.id;
const password = req.body.password;
// λ‘κ·ΈμΈ μ€ν¨κΈ°λ‘ κ°μ Έμ€κΈ°
const loginFailCount = getUserLoginFailCount(id);
// λ‘κ·ΈμΈ μ€ν¨νμ μ΄κ³Όλ‘ μΈν΄ μ κΈλ κ³μ μ λν μΈμ¦ μλ μ ν
if (loginFailCount >= LOGIN_TRY_LIMIT) {
return res.send("account lock(too many failed)")
}
// ν΄μ μμ±μ μνΈλ₯Ό μ¬μ©νλ κ²μ΄ μμ νλ, μ½λμ 볡μ‘μ±μ νΌνκΈ° μν΄ μλ΅
const hashPassword = crypto.createHash("sha512").update(password).digest("base64");
const currentHashPassword = getUserPasswordFromDB(id);
if (hashPassword === currentHashPassword) {
deleteUserLoginFailCount(id);
return res.send("login success");
} else {
updateUserLoginFailCount(id);
return res.send("login fail")
}
}); |
Javascript | μκ° λ° μν | μ’
λ£λμ§ μλ λ°λ³΅λ¬Έ
λλ μ¬κ·ν¨μ | μ’
λ£μ‘°κ±΄ μλ μ μ΄λ¬Έ μ¬μ©μΌλ‘ λ°λ³΅λ¬Έ λλ μ¬κ·ν¨μκ° λ¬΄νν λ°λ³΅λμ΄ λ°μν μ μλ 보μμ½μ | function factorial(x) {
# μ¬κ·ν¨μ νμΆμ‘°κ±΄μ μ€μ νμ§ μμ λμ μ€ μλ¬ λ°μ
return x * factorial(x - 1);
}); | function factorial(x) {
# μ¬κ·ν¨μ μ¬μ© μμλ νμΆ μ‘°κ±΄μ λͺ
μν΄μΌ νλ€
if ( x === 0 ) {
return;
}
else {
return x * factorial(x - 1);
}
} |
Javascript | μλ¬μ²λ¦¬ | μ€λ₯ λ©μμ§ μ 보λ
ΈμΆ | μ€λ₯λ©μμ§λ μ€νμ 보μ μμ€ν
λ΄λΆκ΅¬μ‘°κ° ν¬ν¨λμ΄ λ―Όκ°ν μ 보, λλ²κΉ
μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | const express = require('express');
const fs = require("fs");
router.get("/vuln", (req, res) => {
const filePath = "./file/secret/password";
fs.readFile(filePath, (err, data) => {
if (err) {
// μλ² λ΄λΆμμ λ°μν μλ¬ λ©μμ§λ₯Ό κ·Έλλ‘ μ¬μ©μμ μ λ¬ν΄ μ£Όμ μ 보 λ
ΈμΆ μν
return res.status(500).send(err);
} else {
return res.send(data);
}
})
}); | const express = require('express');
const fs = require("fs");
router.get("/vuln", (req, res) => {
const filePath = "./file/secret/password";
fs.readFile(filePath, (err, data) => {
if (err) {
// μλ¬ λ΄μ©μ κ·Έλλ‘ μ λ¬νμ§ μκ³ νν°λ§ μ²λ¦¬
return res.status(500).send({ message: βμλͺ»λ μμ²μ
λλ€β });
} else {
return res.send(data);
}
})
}); |
Javascript | μλ¬μ²λ¦¬ | μ€λ₯ λ©μμ§ μ 보λ
ΈμΆ | μ€λ₯λ©μμ§λ μ€νμ 보μ μμ€ν
λ΄λΆκ΅¬μ‘°κ° ν¬ν¨λμ΄ λ―Όκ°ν μ 보, λλ²κΉ
μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | Expressμμ μ 곡νλ errorHandler λ―Έλ€μ¨μ΄λ₯Ό μ μνμ§ μμ. | const express = require("express");
const app = express();
// errorHandler λ―Έλ€μ¨μ΄λ λ€λ₯Έ app.use() λ° λΌμ°ν° μ μ ν κ°μ₯ λ§μ§λ§μ μ μν΄μΌ νλ©°, // errorHandler λ―Έλ€μ¨μ΄λ₯Ό 컀μ€ν
νμ¬ μλ¬λ³ μλ¬νμ΄μ§λ₯Ό λ°νν μ μλ€
app.use(clientErrorHandler);
app.use(errorHandler);
function clientErrorHandler (err, req, res, next) {
if (req.xhr) {
res.status(500).send({ error: 'Something failed!' });
} else {
next(err);
}
}
function errorHandler (err, req, res, next) {
if (err.name = "ValidError") {
res.status(400)
res.render('400error', { error: err })
} else if (err.name = "AuthError") {
res.status(401)
res.render('401error', { error: err })
} else if (err.name = "ForbiddenError") {
res.status(403)
res.render('403error', { error: err })
} else if (err.name = "DBError") {
res.status(500)
res.render('500error', { error: err })
}
} |
Javascript | μλ¬μ²λ¦¬ | μ€λ₯μν© λμ λΆμ¬ | μμ€ν
μ€λ₯μν©μ μ²λ¦¬νμ§ μμ νλ‘κ·Έλ¨ μ€νμ μ§ λ± μλνμ§ μμ μν©μ΄ λ°μ κ°λ₯ν 보μμ½μ | const express = require('express');
const crypto = require("crypto");
const staticKeys = [
{ "key" : "a6823ecf34012b1ca5ca7889f4eabb51", "iv" : "e79ce03b4563647a" },
{ "key" : "9e7c30e899f296a1daca7d9a0f92e71c", "iv" : "ab39941053fb5f6a" }
];
router.post("/vuln", (req, res) => {
let statickKey = { "key" : "00000000000000000000000000000000", "iv" : "0000000000000000" };
const inputText = req.body.text;
const keyId = req.body.id;
try {
staticKey.key = staticKeys[keyId].key;
staticKey.iv = staticKeys[keyId].iv;
} catch (err) {
// key μ ν μ€ μ€λ₯ λ°μ μ κΈ°λ³ΈμΌλ‘ μ€μ λ μνΈν ν€μΈ
// β0000000000000000β μΌλ‘ μνΈνκ° μνλ¨
console.log(err);
}
const cipher = crypto.createCipheriv('aes-256-cbc', statickKey.key, statickKey.iv);
const encryptedText = cipher.update(inputText, 'utf8', 'base64') + cipher.final('base64');
return res.send(encryptedText);
}); | const express = require('express');
const crypto = require("crypto");
const staticKeys = [
{ "key" : "a6823ecf34012b1ca5ca7889f4eabb51", "iv" : "e79ce03b4563647a" },
{ "key" : "9e7c30e899f296a1daca7d9a0f92e71c", "iv" : "ab39941053fb5f6a" }
];
router.post("/vuln", (req, res) => {
let statickKey = { "key" : "00000000000000000000000000000000", "iv" : "0000000000000000"
};
const inputText = req.body.text;
const keyId = req.body.id;
try {
staticKey.key = staticKeys[keyId].key;
staticKey.iv = staticKeys[keyId].iv;
} catch (err) {
// ν€ μ ν μ€ μ€λ₯ λ°μ μ λλ€μΌλ‘ μνΈν ν€λ₯Ό μμ±νλλ‘ μ€μ
staticKey.key = crypto.randomBytes(16).toString('hex');
staticKey.iv = crypto.randomBytes(8).toString('hex');
}
const cipher = crypto.createCipheriv('aes-256-cbc', statickKey.key, statickKey.iv);
const encryptedText = cipher.update(inputText, 'utf8', 'base64') + cipher.final('base64');
return res.send(encryptedText);
}); |
Javascript | μλ¬μ²λ¦¬ | λΆμ μ ν μμΈμ²λ¦¬ | μμΈμ¬νμ λΆμ μ νκ² μ²λ¦¬νμ¬ μλνμ§ μμ μν©μ΄ λ°μ κ°λ₯ν 보μμ½μ | const express = require('express');
router.post("/vuln", (req, res) => {
const password = req.body.password;
const user = {
user: "user",
password: password,
};
function getUser() {
return new Promise((resolve, reject) => {
resolve(user);
});
}
function getUserPassword(user) {
return new Promise((resolve, reject) => {
if (user.password === undefined) {
reject(new Error("login fail"));
} else {
resolve(user);
}
});
}
function checkPassword(user) {
return new Promise((resolve, reject) => {
if (user.password == "abc") {
resolve(user);
} else {
reject(new Error("login fail"));
}
});
}
return getUser()
.then(getUserPassword)
.then(checkPassword)
.then((result) => res.send(result))
.catch((err) => {
// μλ‘ λ€λ₯Έ μμΈ μν©μμλ λμΌν μλ¬ λ©μμ§λ§ μΆλ ₯
res.send(err.message);
});
}); | const express = require('express');
router.post("/patched", (req, res) => {
const password = req.body.password;
const user = {
user: "user",
password: password,
};
function getUser() {
return new Promise((resolve, reject) => {
resolve(user);
});
}
function getUserPassword(user) {
return new Promise((resolve, reject) => {
if (user.password === undefined) {
reject(new Error("password required"));
}
resolve(user);
});
}
function checkPassword(user) {
return new Promise((resolve, reject) => {
if (user.password == "abc") {
resolve(user);
} else {
reject(new Error("wrong password"));
}
});
}
return getUser()
.then(getUserPassword)
.then(checkPassword)
.then((result) => res.send(result))
.catch((err) => {
// μμΈ μν©μ λ§λ μ²λ¦¬ κ²°κ³Ό λ©μμ§λ₯Ό λ‘κ·Έμ κΈ°λ‘(λ΄μ₯ ν¨μ logκ° μλ€κ³ κ°μ )
log(err.messsage);
// ν΄λΌμ΄μΈνΈμλ μλ¬ λ°μ μ¬λΆλ§ μ λ¬
res.send(βlogin failedβ);
});
); |
Javascript | μ½λμ€λ₯ | Null Pointer μμ°Έμ‘° | λ³μμ μ£Όμ κ°μ΄ NullμΈ κ°μ²΄λ₯Ό μ°Έμ‘°νλ 보μμ½μ | const express = require('express');
router.get("/vuln", (req, res) => {
const id = req.query.id;
// μ¬μ©μκ° id κ°μ μ λ¬νμ§ μμ κ²½μ°(undefined) μλ¬ λ°μ
return res.send("length = " + id.length);
}); | const express = require('express');
router.get("/patched", (req, res) => {
const id = req.query.id;
if (id === undefined) {
// id κ°μ΄ μ λ¬λμ§ μμ κ²½μ° μ¬μ©μμκ² μꡬνλ μμΈ μ½λ μΆκ°
return res.send("id is required");
} else {
return res.send("length = " + id.length);
}
}); |
Javascript | μ½λμ€λ₯ | λΆμ μ ν μμ ν΄μ | μ¬μ© μλ£λ μμμ ν΄μ νμ§ μμ μμμ΄ κ³ κ°λμ΄ μλ‘μ΄ μ
λ ₯μ μ²λ¦¬ν μ μλ 보μμ½μ | const express = require('express');
const fs = require('fs');
router.get("/vuln", (req, res) => {
const configPath = './config.cfg';
let fid = null;
let fdata = null;
try {
fid = fs.openSync(configPath, 'r');
fdata = fs.readFileSync(fid, 'utf8');
// μμΈ λ°μ μν© κ°μ : μ ν¨νμ§ μμ νμΌ λμ€ν¬λ¦½ν°λ‘ νμΌ μ½κΈ° μλ
fdata = fs.readFileSync('100', 'utf8');
// try μ μμ ν λΉλ μμμ΄ λ°ν(close)λκΈ° μ μ μμΈκ° λ°μνλ©΄
// ν λΉλ μμμ΄ μμ€ν
μ λ°λ‘ λ°νλμ§ μμ
fs.close(fid, err => {
if (err) {
console.log('error occured while flle closing');
} else {
console.log('file closed');
}
});
} catch (e) {
console.log('error occured!' , e);
}
return res.send(fdata);
}); | const express = require('express');
const fs = require('fs');
router.get("/patched", (req, res) => {
const configPath = './5_code_error/40_improper_resource_shutdown/config.cfg';
let fid = null;
let fdata = null;
try {
fid = fs.openSync(configPath, 'r');
fdata = fs.readFileSync(fid, 'utf8');
fdata = fs.readFileSync(100, 'utf8');
} catch (e) {
console.log('error occured!' , e);
// try μ μμ ν λΉλ μμμ finally μ μμ μμ€ν
μ λ°νμ ν΄μΌ ν¨
} finally {
fs.close(fid, err => {
if (err) {
console.log('error occured while flle closing');
} else {
console.log('file closed');
}
});
}
return res.send(fdata);
}); |
Javascript | μ½λμ€λ₯ | μ λ’°ν μ μλ
λ°μ΄ν°μ μμ§λ ¬ν | μ
μμ μΈ μ½λκ° μ½μ
Β·μμ λ μ§λ ¬ν λ°μ΄ν°λ₯Ό μ μ ν κ²μ¦ μμ΄ μμ§λ ¬ννμ¬ λ°μνλ 보μμ½μ
* μ§λ ¬ν: κ°μ²΄λ₯Ό μ μ‘ κ°λ₯ν λ°μ΄ν°νμμΌλ‘ λ³ν
* μμ§λ ¬ν: μ§λ ¬νλ λ°μ΄ν°λ₯Ό μλ κ°μ²΄λ‘ 볡μ | const express = require('express');
def load_user_object(request):
const serializedData = req.query.data;
# μ¬μ©μλ‘λΆν° μ
λ ₯λ°μ μ μ μλ λ°μ΄ν°λ₯Ό μμ§λ ¬ν
const user = JSON.parse(serializedData);
return res.send({user: user.user, isAdmin: user.isAdmin}); | const express = require('express');
const crypto = require('crypto');
def load_user_object(request):
const serializedData = req.query.data;
# λ°μ΄ν° νμ: '{"userInfo":{"user":"admin","isAdmin":true},"hashed":"cf8cd...7"}';
const body = JSON.parse(serializedData);
# λ°μ΄ν° λ³μ‘°λ₯Ό νμΈνκΈ° μν ν΄μκ°
const hashedMac = body.hashed;
# μ¬μ©μλ‘λΆν° μ
λ ₯λ°μ λ°μ΄ν°λ₯Ό μ§λ ¬ν
const userInfo = JSON.stringify(body.userInfo);
const secretKey = 'secret_key';
const hmac = crypto.createHmac('sha512', secretKey);
# μ§λ ¬νλ μ¬μ©μ μ
λ ₯κ°μ ν΄μ±
hmac.update(userInfo);
const calculatedHMAC = hmac.digest('hex');
# μ λ¬λ°μ ν΄μκ°(hashedMAC)κ³Ό μ§λ ¬ν λ°μ΄ν°(calculaedHMAC)μ ν΄μκ°μ λΉκ΅νμ¬ κ²μ¦
if (calculatedHMAC === hashedMac) {
const userObj = JSON.parse(userInfo);
return res.send(userObj);
} else {
console.log('hmac -', calculatedHMAC);
return res.send('μ λ’°ν μ μλ λ°μ΄ν°μ
λλ€. ');
} |
Javascript | μΊ‘μν | μλͺ»λ μΈμ
μ μν
λ°μ΄ν° μ 보λ
ΈμΆ | μλͺ»λ μΈμ
μ μν΄ μΈκ°λμ§ μμ μ¬μ©μμκ² μ€μμ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | let instance;
class UserSingleton {
constructor() {
this.userName = 'testUser';
if (instance) {
return instance;
}
instance = this;
}
getUserProfile() {
return this.userName;
}
};
router.get("/vuln", (req, res) => {
const user = new UserSingleton();
const profile = user.getUserProfile();
// μλ‘ λ€λ₯Έ μΈμ
μμ 곡μ λλ κ°μ μ¬μ©νλ κ²½μ° λ€λ₯Έ μΈμ
μ μν΄ λ°μ΄ν°κ° λ
ΈμΆλ μ μμ
return res.send(profile);
}); | class User {
constructor() {
this.userName = 'testUser';
}
getUserProfile() {
return this.userName;
}
};
router.get("/patched", (req, res) => {
const user = new User();
const profile = user.getUserProfile();
// μλ‘ λ€λ₯Έ μΈμ
μμ 곡μ λμ§ μλ ν΄λμ€ μ μλ₯Ό μ¬μ©ν΄ μμ ν¨
return res.send(profile);
}); |
Javascript | μΊ‘μν | μ κ±°λμ§ μκ³ λ¨μ
λλ²κ·Έ μ½λ | λλ²κΉ
μ μν μ½λλ₯Ό μ κ±°νμ§ μμ μΈκ°λμ§ μμ μ¬μ©μμκ² μ€μμ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | λλ²κΉ
λͺ©μ μΌλ‘ μ½μ
λ μ½λλ κ°λ°μ΄ μλ£λλ©΄ μ κ±°ν΄μΌ νλ€. λλ²κ·Έ μ½λλ μ€μ λ±μ λ―Όκ°ν μ 보 λλ
μλνμ§ μμ μμ€ν
μ μ΄λ‘ μ΄μ΄μ§λ μ 보λ₯Ό λ΄κ³ μμ μ μλ€. λ§μΌ λλ²κ·Έ μ½λκ° λ¨κ²¨μ§ μ±λ‘ λ°°ν¬λ
κ²½μ° κ³΅κ²©μκ° μλ³ κ³Όμ μ μ°ννκ±°λ μλνμ§ μμ μ 보 λ
ΈμΆ λ¬Έμ κ° λ°μν μ μλ€. κΈ°λ³Έμ μΌλ‘ μλ°μ€ν¬λ¦½νΈμμλ console.log λλ console.error ν¨μλ₯Ό μ¬μ©ν΄ λλ²κ·Έ λ©μμ§λ₯Ό μΆλ ₯νλ€. κ°λ° μλ£ νμ λλ²κΉ
μ©μΌλ‘ μμ±ν μ½λλ₯Ό μ€λ²λΌμ΄λ(override) ν΄ μ ν리μΌμ΄μ
λμ μ μ½μ λ‘κ·Έκ° μΆλ ₯
λμ§ μλλ‘ νλ€. λν κΈ°λ³Έμ μΌλ‘ ExpressJSλ λλ²κ·Έ λͺ¨λκ° λΉνμ±ν λ μνμμ λμνλ©° μλ² κ΅¬λ μ
βDEBUG=β prefix μ€μ μ νμ§ μλ ν μλ² λλ²κΉ
λ©μμ§λ μΆλ ₯νμ§ μλλ€. | // μ ν리μΌμ΄μ
μ§μ
μ½λμΈ Index.jsμ λ€μ μ½λλ₯Ό μΆκ°νλ©΄
// μ½λ λ΄μ μμ λμ§ μμ λͺ¨λ console.log μ½λλ‘ μΈν΄ μλ¬΄λ° λ΄μ©λ μΆλ ₯λμ§ μμ
// ReactJS μμ
if (process.env.NODE_ENV === βproductionβ && typeof window !== βundefinedβ) {
console.log = () => {};
} |
Javascript | μΊ‘μν | μ κ±°λμ§ μκ³ λ¨μ
λλ²κ·Έ μ½λ | λλ²κΉ
μ μν μ½λλ₯Ό μ κ±°νμ§ μμ μΈκ°λμ§ μμ μ¬μ©μμκ² μ€μμ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | λλ²κΉ
λͺ©μ μΌλ‘ μ½μ
λ μ½λλ κ°λ°μ΄ μλ£λλ©΄ μ κ±°ν΄μΌ νλ€. λλ²κ·Έ μ½λλ μ€μ λ±μ λ―Όκ°ν μ 보 λλ
μλνμ§ μμ μμ€ν
μ μ΄λ‘ μ΄μ΄μ§λ μ 보λ₯Ό λ΄κ³ μμ μ μλ€. λ§μΌ λλ²κ·Έ μ½λκ° λ¨κ²¨μ§ μ±λ‘ λ°°ν¬λ
κ²½μ° κ³΅κ²©μκ° μλ³ κ³Όμ μ μ°ννκ±°λ μλνμ§ μμ μ 보 λ
ΈμΆ λ¬Έμ κ° λ°μν μ μλ€. κΈ°λ³Έμ μΌλ‘ μλ°μ€ν¬λ¦½νΈμμλ console.log λλ console.error ν¨μλ₯Ό μ¬μ©ν΄ λλ²κ·Έ λ©μμ§λ₯Ό μΆλ ₯νλ€. κ°λ° μλ£ νμ λλ²κΉ
μ©μΌλ‘ μμ±ν μ½λλ₯Ό μ€λ²λΌμ΄λ(override) ν΄ μ ν리μΌμ΄μ
λμ μ μ½μ λ‘κ·Έκ° μΆλ ₯
λμ§ μλλ‘ νλ€. λν κΈ°λ³Έμ μΌλ‘ ExpressJSλ λλ²κ·Έ λͺ¨λκ° λΉνμ±ν λ μνμμ λμνλ©° μλ² κ΅¬λ μ
βDEBUG=β prefix μ€μ μ νμ§ μλ ν μλ² λλ²κΉ
λ©μμ§λ μΆλ ₯νμ§ μλλ€. | // μλ² μ§μ
μ½λμΈ index.js λ΄μ μλ² κ΅¬λ λΆλΆμ λ€μ μ½λ μΆκ°
// ExpressJS μμ
app.listen(80, () => {
if (!process.env.DEBUG) {
console.log = function(){}
}
}); |
Javascript | μΊ‘μν | Public λ©μλλ‘λΆν° λ°νλ Private λ°°μ΄ | PublicμΌλ‘ μ μΈλ λ©μλμμ Privateλ‘ μ μΈλ λ°°μ΄μ λ°ν(return)νλ©΄ Private λ°°μ΄μ μ£Όμ
κ°μ΄ μΈλΆμ λ
ΈμΆλμ΄ ν΄λΉ Private λ°°μ΄κ°μ μΈλΆμμ μμ κ°λ₯ν 보μμ½μ | class UserObj {
#privArray = [];
// private λ°°μ΄μ 리ν΄νλ public λ©μλλ₯Ό μ¬μ©νλ κ²½μ° μ·¨μ½
get_private_member = () => {
return this.#privArray;
}
} | class UserObj {
#privArray = [];
// private λ°°μ΄μ λ°ννλ κ²½μ° λ³΅μ¬λ³Έμ μ¬μ©ν΄ μΈλΆμ λ΄λΆμ
// λ°°μ΄μ΄ μλ‘ μ°Έμ‘°λμ§ μλλ‘ ν΄μΌ ν¨
get_private_member = () => {
const copied = Object.assign([], this.#privArray);
return copied;
}
} |
Javascript | μΊ‘μν | Private λ°°μ΄μ Public
λ°μ΄ν° ν λΉ | PublicμΌλ‘ μ μΈλ λ°μ΄ν° λλ λ©μλμ μΈμκ° Privateλ‘ μ μΈλ λ°°μ΄μ μ μ₯λλ©΄ Private λ°°μ΄μ μΈλΆμμ μ κ·Όνμ¬ μμ κ°λ₯ν 보μμ½μ | class UserObj {
#privArray = [];
// private λ°°μ΄μ μΈλΆ κ°μ λ°λ‘ λμ
νλ public λ©μλλ₯Ό μ¬μ©νλ κ²½μ° μ·¨μ½
set_private_member = (input_list) => {
this.#privArray = input_list;
}
} | class UserObj2 {
#privArray = [];
// μ¬μ©μκ° μ λ¬ν κ°μ privateκ° μλ public λ°°μ΄λ‘ μ μ₯
set_private_member = (input_list) => {
this.userInput = input_list;
}
} |
Javascript | API μ€μ© | DNS lookupμ μμ‘΄ν
보μκ²°μ | λλ©μΈλͺ
νμΈ(DNS lookup)μΌλ‘ 보μκ²°μ μ μνν λ μ
μμ μΌλ‘ λ³μ‘°λ DNS μ λ³΄λ‘ μκΈ°μΉ μμ 보μμνμ λ
ΈμΆλλ 보μμ½μ | const express = require('express');
const dns = require("dns");
router.get("/vuln", (req, res) => {
let trusted = false;
const trustedHost = "www.google.com";
const hostName = req.query.host;
// 곡격μμ μν΄ μ€νλλ μλ²μ DNSκ° λ³κ²½λ μ μμΌλ―λ‘
// μμ νμ§ μμ
if (hostName === trustedHost) {
trusted = true;
}
return res.send({trusted});
}); | const express = require('express');
const dns = require("dns");
router.get("/patched", async (req, res) => {
let trusted = false;
const trustedHost = "142.250.207.100";
// μ€μ μλ²μ IP μ£Όμλ₯Ό λΉκ΅νμ¬ DNS λ³μ‘°μ λμ
async function dnsLookup() {
return new Promise((resolve, reject) => {
dns.lookup(req.query.host, 4, (err, address, family) => {
if (err) reject(err);
resolve(address);
})
})
}
const hostName = await dnsLookup();
if (hostName === trustedHost) {
trusted = true;
}
return res.send({trusted});
}); |
Javascript | API μ€μ© | μ·¨μ½ν API μ¬μ© | eval() ν¨μμ λΆμ μ ν μ¬μ© | const userInput = "2 + 2";
const result = eval(userInput); // μ¬μ©μ μ
λ ₯μ νκ°νμ¬ μ€ν
console.log(result); | const math = require('mathjs');
const userInput = "2 + 2";
const result = math.evaluate(userInput); // μμ ν μν ννμ νκ°
console.log(result); |
Javascript | API μ€μ© | μ·¨μ½ν API μ¬μ© | innerHTML μμ±μ λΆμ μ ν μ¬μ© | const userInput = "<img src='x' onerror='alert(1)'>";
document.getElementById('output').innerHTML = userInput; | const userInput = "<img src='x' onerror='alert(1)'>";
const outputElement = document.getElementById('output');
const textNode = document.createTextNode(userInput);
outputElement.appendChild(textNode); |
Javascript | API μ€μ© | μ·¨μ½ν API μ¬μ© | setTimeout() λ° setInterval() ν¨μμ λΆμ μ ν μ¬μ© | const userInput = "alert('Hello')";
setTimeout(userInput, 1000); // μ¬μ©μ μ
λ ₯μ μ½λλ‘ μ€ν | const userInput = "Hello";
setTimeout(() => {
alert(userInput);
}, 1000); |
Javascript | API μ€μ© | μ·¨μ½ν API μ¬μ© | Function μμ±μμ λΆμ μ ν μ¬μ© | const userInput = "return 2 + 2";
const func = new Function(userInput);
console.log(func()); | const userInput = "2 + 2";
const result = eval(userInput); // eval μ¬μ©μ μ§μν΄μΌ νμ§λ§, μμλ₯Ό μν΄ μ¬μ©
console.log(result); |
Javascript | API μ€μ© | μ·¨μ½ν API μ¬μ© | document.write() ν¨μμ λΆμ μ ν μ¬μ© | const userInput = "<script>alert('XSS')</script>";
document.write(userInput); | const userInput = "Hello, World!";
const outputElement = document.getElementById('output');
const textNode = document.createTextNode(userInput);
outputElement.appendChild(textNode); |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | SQL μ½μ
| SQL μ§μλ¬Έμ μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ§μλ¬Έμ΄ μ€νκ°λ₯ν
보μμ½μ | from django.shortcuts import render
from django.db import connection
def update_board(request):
......
dbconn = connection
with dbconn.cursor() as curs:
# μΈλΆλ‘λΆν° μ
λ ₯λ°μ κ°μ κ²μ¦ μμ΄ μ¬μ©ν κ²½μ° μμ νμ§ μλ€
name = request.POST.get('name', '') content_id = request.POST.get('content_id', '') # μ¬μ©μμ κ²μ¦λμ§ μμ μ
λ ₯κ°μ μ¬μ©ν΄ λμ 쿼리문 μμ±
sql_query = "update board set name='" + name + "' where content_id='β + content_id + "'"
# μΈλΆ μ
λ ₯κ°μ΄ κ²μ¦ μμ΄ μΏΌλ¦¬λ‘ ν¬ν¨λμ΄ μμ νμ§ μλ€
curs.execute(sql_query) dbconn.commit()
return render(request, '/success.html') | from django.shortcuts import render
from django.db import connection
def update_board(request): ......
dbconn = connection
with dbconn.cursor() as curs:
name = request.POST.get('name', '')
content_id = request.POST.get('content_id', '')
# μΈλΆ μ
λ ₯κ° μ‘°μμΌλ‘λΆν° μμ ν μΈμνλ 쿼리λ₯Ό μμ±νλ€.
sql_query = 'update board set name=%s where content_id=%s'
# μ¬μ©μμ μ
λ ₯κ°μ΄ μΈμνλ 쿼리μ λ°μΈλ© ν μ€νλλ―λ‘ μμ νλ€.
curs.execute(sql_query, (name, content_id))
dbconn.commit()
return render(request, '/success.html') |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | SQL μ½μ
| SQL μ§μλ¬Έμ μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ§μλ¬Έμ΄ μ€νκ°λ₯ν
보μμ½μ | from django.shortcuts import render
from app.models import Member
def member_search(request):
name = request.POST.get('name', '')
# μ
λ ₯κ°μ κ²μ¦ μμ΄ μΏΌλ¦¬λ¬Έ μμ±μ μ¬μ©ν΄ μμ νμ§ μλ€
query=βselect * from member where name=ββ + name + βββ # μΈλΆ μ
λ ₯κ°μ κ²μ¦ μμ΄ μ¬μ©ν 쿼리문μ raw()ν¨μλ‘ μ€ννλ©΄ μμ νμ§ μλ€
data = Member.objects.raw(query)
return render(request, '/member_list.html', {'member_list':data}) | from django.shortcuts import render
from app.models import Member
def member_search(request):
name = request.POST.get('name', '')
# μΈλΆ μ
λ ₯κ°μ raw() ν¨μ μ€ν μ λ°μΈλ© λ³μλ‘ μ¬μ©νμ¬ μΏΌλ¦¬ ꡬ쑰κ°
# λ³κ²½λμ§ μλλ‘ νλ€.(list νμ %s, dictionary νμ %(key)sλ₯Ό μ¬μ©)
query='select * from member where name=%s'
# μΈμνλ 쿼리문μ μ¬μ©νμ¬ raw() ν¨μλ₯Ό νΈμΆν΄ μμ νλ€
data = Member.objects.raw(query, [name])
return render(request, '/member_list.html', {'member_list':data}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ½λ μ½μ
| νλ‘μΈμ€κ° μΈλΆ μ
λ ₯κ°μ μ½λ(λͺ
λ Ήμ΄)λ‘ ν΄μΒ·μ€νν μ μκ³ νλ‘μΈμ€μ κ²μ¦λμ§ μμ μΈλΆ
μ
λ ₯κ°μ νμ©ν κ²½μ° μ
μμ μΈ μ½λκ° μ€ν κ°λ₯ν 보μμ½μ | from django.shortcuts import render
def route(request):
# μΈλΆμμ μ
λ ₯λ°μ κ°μ κ²μ¦ μμ΄ μ¬μ©νλ©΄ μμ νμ§ μλ€
message = request.POST.get('message', '')
# μΈλΆ μ
λ ₯κ°μ κ²μ¦ μμ΄ eval ν¨μμ μ λ¬ν κ²½μ° μλνμ§ μμ μ½λκ°
# μ€νλ μ μμ΄ μννλ€
ret = eval(message)
return render(request, '/success.html', {'data':ret}) | from django.shortcuts import render
def route(request):
message = request.POST.get('message', '')
# μ¬μ©μ μ
λ ₯μ μλ¬Έ, μ«μλ‘ μ ννλ©°, λ§μ½ μ
λ ₯κ° λ΄μ νΉμλ¬Έμκ° ν¬ν¨λμ΄
# μμ κ²½μ° μλ¬ λ©μμ§λ₯Ό λ°ν νλ€
if message.isalnum():
ret = eval(message)
return render(request, '/success.html', {'data':ret})
return render(request, '/error.html') |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ½λ μ½μ
| νλ‘μΈμ€κ° μΈλΆ μ
λ ₯κ°μ μ½λ(λͺ
λ Ήμ΄)λ‘ ν΄μΒ·μ€νν μ μκ³ νλ‘μΈμ€μ κ²μ¦λμ§ μμ μΈλΆ
μ
λ ₯κ°μ νμ©ν κ²½μ° μ
μμ μΈ μ½λκ° μ€ν κ°λ₯ν 보μμ½μ | from django.shortcuts import render
def request_rest_api(request):
function_name = request.POST.get('function_name', '')
# μ¬μ©μμκ² μ λ¬λ°μ ν¨μλͺ
μ κ²μ¦νμ§ μκ³ μ€ν
# μ
λ ₯κ°μΌλ‘ β__import__(βplatformβ).system()β λ±μ μ
λ ₯ μ
# μμ€ν
μ 보 λ
ΈμΆ μνμ΄ μλ€
exec('{}()'.format(function_name))
return render(request, '/success.html') | from django.shortcuts import render
WHITE_LIST = ['get_friends_list', 'get_address', 'get_phone_number']
def request_rest_api(request):
function_name = request.POST.get('function_name', '')
# μ¬μ© κ°λ₯ν ν¨μλ₯Ό νμ΄νΈλ¦¬μ€νΈ λͺ©λ‘ λ΄μ ν¨μλ‘ μ ν
if function_name in WHITE_LIST:
exec('{}()'.format(function_name))
return render(request, '/success.html')
return render(request, '/error.html', {'error':'νμ©λμ§ μμ ν¨μμ
λλ€.'}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | κ²½λ‘ μ‘°μ λ° μμ μ½μ
| μμ€ν
μμ μ κ·Όκ²½λ‘ λλ μμμ μ΄ λͺ
λ Ήμ΄μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μμ€ν
μμμ λ¬΄λ¨ μ κ·Ό λ° μ
μμ μΈ νμκ° κ°λ₯ν 보μμ½μ | import os
from django.shortcuts import render
def get_info(request):
# μΈλΆ μ
λ ₯κ°μΌλ‘λΆν° νμΌλͺ
μ μ
λ ₯ λ°λλ€
request_file = request.POST.get('request_file')
(filename, file_ext) = os.path.splitext(request_file)
file_ext = file_ext.lower()
if file_ext not in ['.txt', '.csv']:
return render(request, '/error.html', {'error':'νμΌμ μ΄ μ μμ΅λλ€.'})
# μ
λ ₯κ°μ κ²μ¦ μμ΄ νμΌ μ²λ¦¬μ μ¬μ©νλ€
with open(request_file) as f:
data = f.read()
return render(request, '/success.html', {'data':data}) | import os
from django.shortcuts import render
def get_info(request):
request_file = request.POST.get('request_file')
(filename, file_ext) = os.path.splitext(request_file)
file_ext = file_ext.lower()
# μΈλΆ μ
λ ₯κ°μΌλ‘ λ°μ νμΌ μ΄λ¦μ κ²μ¦νμ¬ μ¬μ©νλ€.
if file_ext not in ['.txt', '.csv']:
return render(request, '/error.html', {'error':'νμΌμ μ΄μ μμ΅λλ€.'})
# νμΌ λͺ
μμ κ²½λ‘ μ‘°μ λ¬Έμμ΄μ νν°λ§ νλ€.
filename = filename.replace('.', '')
filename = filename.replace('/', '')
filename = filename.replace('\\', '')
try:
with open(filename + file_ext) as f:
data = f.read()
except Exception:
return render(
request, "/error.html", {"error": "νμΌμ΄ μ‘΄μ¬νμ§ μκ±°λ μ΄ μ μλ νμΌμ
λλ€."}
)
return render(request, '/success.html', {'data':data}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | κ²½λ‘ μ‘°μ λ° μμ μ½μ
| μμ€ν
μμ μ κ·Όκ²½λ‘ λλ μμμ μ΄ λͺ
λ Ήμ΄μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μμ€ν
μμμ λ¬΄λ¨ μ κ·Ό λ° μ
μμ μΈ νμκ° κ°λ₯ν 보μμ½μ | import socket
from django.shortcuts import render
def get_info(request):
port = int(request.POST.get('port'))
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
# μΈλΆλ‘λΆν° μ
λ ₯λ°μ κ²μ¦λμ§ μμ ν¬νΈ λ²νΈλ₯Ό μ΄μ©νμ¬
# μμΌμ λ°μΈλ©νμ¬ μ¬μ©νκ³ μμ΄ μμ νμ§ μλ€
s.bind(('127.0.0.1', port))
...
return render(request, '/success.html')
return render(request, '/error.html', {'error':'μμΌμ°κ²° μ€ν¨'}) | import socket
from django.shortcuts import render
ALLOW_PORT = [4000, 6000, 9000]
def get_info(request):
port = int(request.POST.get('port'))
# μ¬μ© κ°λ₯ν ν¬νΈ λ²νΈλ₯Ό νμ΄νΈλ¦¬μ€νΈ λ΄μ ν¬νΈλ‘ μ ν
if port not in ALLOW_PORT:
return render(request, '/error.html', {'error':'μμΌμ°κ²° μ€ν¨'})
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('127.0.0.1', port))
......
return render(request, '/success.html') |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μ€ν¬λ¦½νΈ(XSS) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ€ν¬λ¦½νΈκ° μ€ν κ°λ₯ν
보μμ½μ | from django.shortcuts import render
from django.utils.safestring import mark_safe
def profile_link(request):
# μΈλΆ μ
λ ₯κ°μ κ²μ¦ μμ΄ HTML νκ·Έ μμ±μ μΈμλ‘ μ¬μ©
profile_url = request.POST.get('profile_url')
profile_name = requst.POST.get('profile_name')
object_link = '<a href="{}">{}</a>'.format(profile_url, profile_name)
# mark_safeν¨μλ Djangoμ XSS escape μ μ±
μ λ°λ₯΄μ§ μλλ€
object_link = mark_safe(object_link)
return render(request, 'my_profile.html',{'object_link':object_link}) | from django.shortcuts import render
def profile_link(request):
# μΈλΆ μ
λ ₯κ°μ κ²μ¦ μμ΄ HTML νκ·Έ μμ±μ μΈμλ‘ μ¬μ©
profile_url = request.POST.get('profile_url')
profile_name = requst.POST.get('profile_name')
object_link = '<a href="{}">{}</a>'.format(profile_url, profile_name)
# μ λ’°ν μ μλ λ°μ΄ν°μ λν΄μλ mark_safe ν¨μλ₯Ό μ¬μ©ν΄μ μ λλ€
return render(request, 'my_profile.html',{'object_link':object_link}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μ€ν¬λ¦½νΈ(XSS) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ€ν¬λ¦½νΈκ° μ€ν κ°λ₯ν
보μμ½μ | <!doctype html>
<html>
<body>
<div class="content">
{% autoescape off %}
<!-- autoescape offλ‘ μ€μ νλ©΄ ν΄λΉ λΈλ‘λ΄μ λ°μ΄ν°λ XSS 곡격μ
λ
ΈμΆλ μ μλ€ -->
{{ content }}
{% endautoescape %}
</div>
<div class="content2">
<!-- safe νν° μ¬μ©μΌλ‘ XSS 곡격μ λ
ΈμΆλ μ μλ€ -->
{{ content | safe }}
</div>
</body>
</html> | <!doctype html>
<html>
<body>
<div class="content">
{% autoescape on %}
<!--autoescape onμΌλ‘ ν΄λΉ λΈλ‘λ΄μ λ°μ΄ν°λ XSS 곡격μ λ
ΈμΆλμ§ μμ. -->
{{ content }}
{% endautoescape %}
</div>
<div class="content2">
<!-- κ²μ¦λμ§ μμ λ°μ΄ν°μλ safe νν°λ₯Ό μ¬μ©νμ§ μλλ€. -->
{{ content }}
</div>
</body>
</html> |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μ€ν¬λ¦½νΈ(XSS) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ€ν¬λ¦½νΈκ° μ€ν κ°λ₯ν
보μμ½μ | from flask import Flask, request, render_template
@app.route('/search', methods=['POST'])
def search():
search_keyword = request.form.get('search_keyword')
# μ¬μ©μμ μ
λ ₯μ μλ¬΄λ° κ²μ¦ λλ μΉν μμ΄ λμ μΉνμ΄μ§μ μ¬μ©νκ³ μμ΄
# XSS κ³΅κ²©μ΄ λ°μν μ μλ€
return render_template('search.html', search_keyword=search_keyword) | import html
from flask import Flask, request, render_template
@app.route('/search', methods=['POST'])
def search():
search_keyword = request.form.get('search_keyword')
# λμ μΉνμ΄μ§ μμ±μ μ¬μ©λλ λ°μ΄ν°λ
# HTML μν°ν°μ½λλ‘ μΉννμ¬ ννν΄μΌ νλ€
escape_keyword = html.escape(search_keyword)
return render_template('search.html', search_keyword=escape_keyword) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ΄μ체μ λͺ
λ Ήμ΄ μ½μ
| μ΄μ체μ λͺ
λ Ήμ΄λ₯Ό μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ λͺ
λ Ήμ΄κ° μ€ν
κ°λ₯ν 보μμ½μ | import os
from django.shortcuts import render
def execute_command(request):
app_name_string = request.POST.get('app_name','')
# μ
λ ₯ νλΌλ―Έν°λ₯Ό μ ννμ§ μμ μΈλΆ μ
λ ₯κ°μΌλ‘ μ λ¬λ
# λͺ¨λ νλ‘κ·Έλ¨μ΄ μ€νλ μ μμ
os.system(app_name_string)
return render(request, '/success.html') | import os
from django.shortcuts import render
ALLOW_PROGRAM = ['notepad', 'calc']
def execute_command(request):
app_name_string = request.POST.get('app_name','')
# μ
λ ₯λ°μ νλΌλ―Έν°κ° νμ©λ μμ€ν
λͺ
λ Ήμ΄ λͺ©λ‘μ ν¬ν¨λλμ§ κ²μ¬
if app_name_string not in ALLOW_PROGRAM:
return render(request, '/error.html', {'error':'νμ©λμ§ μμ νλ‘κ·Έλ¨μ
λλ€.'})
os.system(app_name_string)
return render(request, '/success.html') |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ΄μ체μ λͺ
λ Ήμ΄ μ½μ
| μ΄μ체μ λͺ
λ Ήμ΄λ₯Ό μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ λͺ
λ Ήμ΄κ° μ€ν
κ°λ₯ν 보μμ½μ | import subprocess
from django.shortcuts import render
def execute_command(request):
date = request.POST.get('date','')
# μ
λ ₯λ°μ νλΌλ―Έν°λ₯Ό μ ννμ§ μμ μ λ¬λ λͺ¨λ νλ‘κ·Έλ¨μ΄ μ€νλ μ μμ
cmd_str = βcmd /c backuplog.bat β + date
subprocess.run(cmd_str, shell=True)
return render(request, '/success.html') | import subprocess
from django.shortcuts import render
def execute_command(request):
date = request.POST.get('date','')
# λͺ
λ Ήμ΄λ₯Ό μΆκ°λ‘ μ€ν λλ λ λ€λ₯Έ λͺ
λ Ήμ΄ μ€νλ μ μλ ν€μλμ
# λν μμΈμ²λ¦¬
for word in ['|', ';', '&', ':', '>', '<', '`', '\\', '!']:
date = date.replace(word, ββ)
# re.sub ν¨μλ₯Ό μ¬μ©ν΄ νΉμλ¬Έμλ₯Ό μ κ±°νλ λ°©λ²λ μλ€
# date = re.sub('[|;&:><`\\\!]', '', date)
# shell=True μ΅μ
μ μ κ±° νκ³ λͺ
λ Ήκ³Ό μΈμλ₯Ό λ°°μ΄λ‘ μ
λ ₯
subprocess.run(["cmd", "/c", "backuplog.bat", date])
return render(request, '/success.html') |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μνν νμ νμΌ μ
λ‘λ | νμΌμ νμ₯μ λ± νμΌνμμ λν κ²μ¦μμ΄ νμΌ μ
λ‘λλ₯Ό νμ©νμ¬ κ³΅κ²©μ΄ κ°λ₯ν 보μμ½μ | from django.shortcuts import render
from django.core.files.storage import FileSystemStorage
def file_upload(request):
if request.FILES['upload_file']:
# μ¬μ©μκ° μ
λ‘λνλ νμΌμ κ²μ¦ μμ΄ μ μ₯νκ³ μμ΄
# μμ νμ§ μλ€
upload_file = request.FILES['upload_file']
fs = FileSystemStorage(location='media/screenshot', base_url='media/screenshot')
# μ
λ‘λ νλ νμΌμ λν ν¬κΈ°, κ°μ, νμ₯μ λ±μ κ²μ¦νμ§ μμ
filename = fs.save(upload_file.name, upload_file)
return render(request, '/success.html', {'filename':filename})
return render(request, '/error.html', {'error':'νμΌ μ
λ‘λ μ€ν¨'}) | import os
from django.shortcuts import render
from django.core.files.storage import FileSystemStorage
# μ
λ‘λ νλ νμΌ κ°μ, ν¬κΈ°, νμ₯μ μ ν
FILE_COUNT_LIMIT = 5
# μ
λ‘λ νλ νμΌμ μ΅λ μ¬μ΄μ¦ μ ν μ ) 5MB - 5*1024*1024
FILE_SIZE_LIMIT = 5242880
# νμ©νλ νμ₯μλ νμ΄νΈλ¦¬μ€νΈλ‘ κ΄λ¦¬νλ€.
WHITE_LIST_EXT = [
'.jpg',
'.jpeg'
]
def file_upload(request):
# νμΌ κ°μ μ ν
if len(request.FILES) == 0 or len(request.FILES) > FILE_COUNT_LIMIT:
return render(request, '/error.html', {'error': 'νμΌ κ°μ μ΄κ³Ό'})
for filename, upload_file in request.FILES.items():
# νμΌ νμ
체ν¬
if upload_file.content_type != 'image/jpeg':
return render(request, '/error.html', {'error': 'νμΌ νμ
μ€λ₯'})
# νμΌ ν¬κΈ° μ ν
if upload_file.size > FILE_SIZE_LIMIT:
return render(request, '/error.html', {'error': 'νμΌμ¬μ΄μ¦ μ€λ₯'})
# νμΌ νμ₯μ κ²μ¬
file_name, file_ext = os.path.splitext(upload_file.name)
if file_ext.lower() not in WHITE_LIST_EXT:
return render(request, '/error.html', {'error': 'νμΌ νμ
μ€λ₯'})
fs = FileSystemStorage(location='media/screenshot', base_url = 'media/screenshot')
for upload_file in request.FILES.values():
filename = fs.save(upload_file.name, upload_file)
filename_list.append(filename)
return render(request, "/success.html", {"filename_list": filename_list}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ λ’°λμ§ μμ URLμ£Όμλ‘ μλμ μ μ°κ²° | URL λ§ν¬ μμ±μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ¬μ΄νΈλ‘ μλ μ μ κ°λ₯ν
보μμ½μ | from django.shortcuts import redirect
def redirect_url(request):
url_string = request.POST.get('url', '')
# μ¬μ©μ μ
λ ₯μ ν¬ν¨λ URL μ£Όμλ‘ λ¦¬λ€μ΄λ νΈ νλ κ²½μ°
# νΌμ± μ¬μ΄νΈλ‘ μ μλλ λ± μ¬μ©μκ° νΌμ± 곡격μ λ
ΈμΆλ μ μλ€
return redirect(url_string) | from django.shortcuts import render, redirect
ALLOW_URL_LIST = [
'127.0.0.1',
'192.168.0.1',
'192.168.0.100',
'https://login.myservice.com',
'/notice',
]
def redirect_url(request):
url_string = request.POST.get('url', '')
# μ΄λν μ μλ URL λ²μλ₯Ό μ ννμ¬
# μνν μ¬μ΄νΈμ μ κ·Όμ μ°¨λ¨νκ³ μλ€
if url_string not in ALLOW_URL_LIST:
return render(request, '/error.html', {'error':'νμ©λμ§ μλ μ£Όμμ
λλ€.'})
return redirect(url_string) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | λΆμ μ ν XML μΈλΆ κ°μ²΄ μ°Έμ‘° | μμλ‘ μ‘°μλ XML μΈλΆκ°μ²΄μ λν μ μ ν κ²μ¦ μμ΄ μ°Έμ‘°λ₯Ό νμ©νμ¬ κ³΅κ²©μ΄ κ°λ₯ν 보μμ½μ | <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ELEMENT foo ANY >
<!ENTITY xxe1 SYSTEM "file:///etc/passwd" >
<!ENTITY xxe2 SYSTEM "http://attacker.com/text.txt">
]>
<foo>&xxe1;&xxe2;</foo>
from xml.sax import make_parser
from xml.sax.handler import feature_external_ges
from xml.dom.pulldom import parseString, START_ELEMENT
from django.shortcuts import render
from .model import comments
def get_xml(request):
if request.method == "GET":
data = comments.objects.all()
com = data[0].comment
return render(request, '/xml_view.html', {'com': com})
elif request.method == "POST":
parser = make_parser()
# μΈλΆ μΌλ° μν°ν°λ₯Ό ν¬ν¨νλ μ€μ μ Trueλ‘ μ μ©ν κ²½μ° μ·¨μ½νλ€
parser.setFeature(feature_external_ges, True)
doc = parseString(request.body.decode('utf-8'), parser=parser)
for event, node in doc:
if event == START_ELEMENT and node.tagName == "foo":
doc.expandNode(node)
text = node.toxml()
comments.objects.filter(id=1).update(comment=text)
return render(request, '/xml_view.html') | from xml.sax import make_parser
from xml.sax.handler import feature_external_ges
from xml.dom.pulldom import parseString, START_ELEMENT
from django.shortcuts import render
from .model import comments
def get_xml(request):
if request.method == βGETβ:
data = comments.objects.all()
com = data[0].comment
return render(request, '/xml_view.html', {'com':com})
elif request.method == βPOSTβ:
parser = make_parser()
parser.setFeature(feature_external_ges, False)
doc = parseString(request.body.decode(βutf-8β), parser=parser)
for event, node in doc:
if event == START_ELEMENT and node.tagName == βfooβ:
doc.expandNode(node)
text = node.toxml()
comments.objects.filter(id=1).update(comment=text);
return render(request, '/xml_view.html') |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | XML μ½μ
| XQuery, XPath μ§μλ¬Έμ μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ§μλ¬Έμ΄
μ€ν κ°λ₯ν 보μμ½μ | from django.shortcuts import render
from lxml import etree
def parse_xml(request):
user_name = request.POST.get('user_name', '')
parser = etree.XMLParser(resolve_entities=False)
tree = etree.parse('user.xml', parser)
root = tree.getroot()
# κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ° user_nameμ μ¬μ©ν μμ νμ§ μμ
# μ§μλ¬Έμ΄ query λ³μμ μ μ₯
query = "/collection/users/user[@name='" + user_name + "']/home/text()"
elmts = root.xpath(query)
return render(request, 'parse_xml.html', {'xml_element':elmts}) | from django.shortcuts import render
from lxml import etree
def parse_xml(request):
user_name = request.POST.get('user_name', '')
parser = etree.XMLParser(resolve_entities=False)
tree = etree.parse('user.xml', parser)
root = tree.getroot()
# μΈλΆ μ
λ ₯κ°μ paramnameμΌλ‘ μΈμν ν΄μ μ¬μ©
query = '/collection/users/user[@name = $paramname]/home/text()' elmts = root.xpath(query, paramname=user_name)
return render(request, 'parse_xml.html', {'xml_element':elmts}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | LDAP μ½μ
| LDAP λͺ
λ Ήλ¬Έμ μμ±ν λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ λͺ
λ Ήμ΄κ° μ€ν
κ°λ₯ν 보μμ½μ | from ldap3 import Connection, Server, ALL
from django.shortcuts import render
config = {
"bind_dn": "cn=read-only-admin,dc=example,dc=com",
"password": "password",
}
def ldap_query(request):
search_keyword = request.POST.get('search_keyword','')
dn = config['bind_dn']
password = config['password']
address = 'ldap.badSoruce.com'
server = Server(address, get_info=ALL)
conn = Connection(server, user=dn, password, auto_bind=True )
# μ¬μ©μ μ
λ ₯μ νν°λ§ νμ§ μλ κ²½μ° κ³΅κ²©μμ κΆν μμΉμΌλ‘
# μ΄μ΄μ§ μ μλ€
search_str = '(&(objectclass=%s))' % search_keyword
conn.search(
'dc=company,dc=com',
search_str,
attributes=['sn', 'cn', 'address', 'mail', 'mobile', 'uid'],
)
return render(request, '/ldap_query_response.html', {'ldap':conn.entries}) | from ldap3 import Connection, Server, ALL
from ldap3.utils.conv import escape_filter_chars
from django.shortcuts import render
config = {
"bind_dn": "cn=read-only-admin,dc=example,dc=com",
"password": "password",
}
def ldap_query(request):
search_keyword = request.POST.get('search_keyword','')
dn = config['bind_dn']
password = config['password']
address = 'ldap.goodsource.com' server = Server(address, get_info=ALL)
conn = Connection(server, dn, password, auto_bind=True )
# μ¬μ©μμ μ
λ ₯μ νν°λ§μ μ μ©νμ¬ κ³΅κ²©μ μ¬μ©λ μ μλ λ¬Έμλ₯Ό
# μ΄μ€μΌμ΄ννκ³ μλ€
escpae_keyword = escape_filter_chars(search_keyword)
search_str = '(&(objectclass=%s))' % escpae_keyword
conn.search(
'dc=company,dc=com',
search_str,
attributes=['sn', 'cn', 'address', 'mail', 'mobile', 'uid'],
)
return render(request, '/ldap_query_response.html', {'ldap':conn.entries}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μμ² μμ‘°(CSRF) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ¬μ©μ λ³ΈμΈμ μμ§μλ 무κ΄νκ²
곡격μκ° μλν νμκ° μ€ν κ°λ₯ν 보μμ½μ | MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
# MIDDLEWARE λͺ©λ‘μμ CSRF νλͺ©μ μμ λλ μ£Όμμ²λ¦¬ νλ©΄
# Django μ±μμ CSRF μ ν¨μ± κ²μ¬κ° μ μμ μΌλ‘ μ κ±°λλ€
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
...... ] | MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
# MIDDLEWARE λͺ©λ‘μμ CSRF νλͺ©μ νμ±ν νλ€
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
...... ] |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μμ² μμ‘°(CSRF) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ¬μ©μ λ³ΈμΈμ μμ§μλ 무κ΄νκ²
곡격μκ° μλν νμκ° μ€ν κ°λ₯ν 보μμ½μ | from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
# csrf.exempt λ°μ½λ μ΄ν°λ‘ λ―Έλ€μ¨μ΄μμ 보νΈλλ CSRF κΈ°λ₯μ ν΄μ νλ€
@csrf.exempt
def pay_to_point(request):
user_id = request.POST.get('user_id', '')
pay = request.POST.get('pay', '')
product_info = request.POST.get('product_info', '')
ret = handle_pay(user_id, pay, product_info)
return render(request, '/view_wallet.html', {'wallet':ret}) | from django.shortcuts import render
from django.template import RequestContext
# csrf_exempt λ°μ½λ μ΄ν°λ₯Ό μμ νκ±°λ μ£Όμ μ²λ¦¬νλ€. # @csrf_exempt
def pay_to_point(request):
user_id = request.POST.get('user_id', '')
pay = request.POST.get('pay', '')
product_info = request.POST.get('product_info', '')
ret = handle_pay(user_id, pay, product_info)
return render(request, '/view_wallet.html', {'wallet':ret}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μμ² μμ‘°(CSRF) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ¬μ©μ λ³ΈμΈμ μμ§μλ 무κ΄νκ²
곡격μκ° μλν νμκ° μ€ν κ°λ₯ν 보μμ½μ | <!--html page-->
<form action="" method="POST">
<!-- form νκ·Έ λ΄λΆμ csrf_token λ―Έμ μ©-->
<table>
{{form.as_table}}
</table>
<input type="submit"/>
</form> | <!--html page-->
<form action="" method="POST"> {% csrf_token %} <!--csrf_token μ¬μ©->
<table>
{{form.as_table}}
</table>
<input type="submit"/>
</form> |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μμ² μμ‘°(CSRF) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ¬μ©μ λ³ΈμΈμ μμ§μλ 무κ΄νκ²
곡격μκ° μλν νμκ° μ€ν κ°λ₯ν 보μμ½μ | from flask import Flask
app = Flask(__name__) | from flask import Flask
from flask_wtf.csrf import CSRFProtect
# CSRF μ€μ μΆκ°
csrf = CSRFProtect(app)
app = Flask(__name__)
app.config[βSECRET_KEYβ] = os.environ.get('SECRET_KEY')
csrf.init_app(app) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ‘μ€μ¬μ΄νΈ μμ² μμ‘°(CSRF) | μ¬μ©μ λΈλΌμ°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ¬μ©μ λ³ΈμΈμ μμ§μλ 무κ΄νκ²
곡격μκ° μλν νμκ° μ€ν κ°λ₯ν 보μμ½μ | <form action="" method="POST">
<!-- form νκ·Έ λ΄λΆμ csrf_token λ―Έμ μ©-->
<table>
{{as_table}}
</table>
<input type="submit"/>
</form> | <form action="" method="POST">
<!-- form νκ·Έ λ΄λΆμ csrf_token μ μ©-->
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<table>
{{table}}
</table>
<input type="submit"/>
</form> |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μλ²μ¬μ΄λ μμ² μμ‘° | μλ² κ° μ²λ¦¬λλ μμ²μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ κ³΅κ²©μκ° μλν μλ²λ‘ μ μ‘νκ±°λ λ³μ‘°νλ 보μμ½μ | from django.shortcuts import render
import requests
def call_third_party_api(request):
addr = request.POST.get('address', '')
# μ¬μ©μκ° μ
λ ₯ν μ£Όμλ₯Ό κ²μ¦νμ§ μκ³ HTTP μμ²μ λ³΄λΈ ν
# μλ΅μ μ¬μ©μμκ² λ°ν
result = requests.get(addr).text
return render(request, '/result.html', {'result':result}) | from django.shortcuts import render
import requests
# νμ©νλ λλ©μΈμ νμ΄νΈλ¦¬μ€νΈμ μ μν κ²½μ° DNS rebinding 곡격 λ±μ
# λ
ΈμΆλ μνμ΄ μμ΄ μ λ’°ν μ μλ μμμ λν IPλ₯Ό μ¬μ©ν΄
# κ²μ¦νλ κ²μ΄ μ‘°κΈ λ μμ νλ€
ALLOW_SERVER_LIST = [
'https://127.0.0.1/latest/',
'https://192.168.0.1/user_data',
'https://192.168.0.100/v1/public',
]
def call_third_party_api(request):
addr = request.POST.get('address', '')
# μ¬μ©μκ° μ
λ ₯ν URLμ νμ΄νΈλ¦¬μ€νΈλ‘ κ²μ¦ν ν κ·Έ κ²°κ³Όλ₯Ό λ°ννμ¬
# κ²μ¦λμ§ μμ μ£Όμλ‘ μμ²μ 보λ΄μ§ μλλ‘ μ ννλ€
if addr not in ALLOW_SERVER_LIST:
return render(request, '/error.html', {βerrorβ = 'νμ©λμ§ μμ μλ²μ
λλ€.'})
result = requests.get(addr).text
return render(request, '/result.html', {'result':result}) |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | HTTP μλ΅λΆν | HTTP μλ΅ν€λμ κ°νλ¬Έμ(CRμ΄λ LF)κ° ν¬ν¨λ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ μ
μμ μΈ μ½λκ° μ€ν κ°λ₯ν 보μμ½μ | from django.http import HttpResponse
def route(request):
content_type = request.POST.get('content-type')
# μΈλΆ μ
λ ₯κ°μ κ²μ¦ λλ νν°λ§ νμ§ μκ³
# μλ΅ ν€λμ κ°μΌλ‘ ν¬ν¨μμΌ νμ νλ€
......
res = HttpResponse()
res['Content-Type'] = content_type
return res | from django.http import HttpResponse
def route(request):
content_type = request.POST.get('content-type')
# μλ΅ν€λμ ν¬ν¨λ μ μλ μΈλΆ μ
λ ₯κ° λ΄μ κ°ν λ¬Έμλ₯Ό μ κ±°νλ€
content_type = content_type.replace('\r', '')
content_type = content_type.replace('\n', '')
......
res = HttpResponse()
res['Content-Type'] = content_type
return res |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | μ μν μ€λ²νλ‘μ° | μ μν λ³μμ μ μ₯λ κ°μ΄ νμ©λ μ μ κ° λ²μλ₯Ό λ²μ΄λ νλ‘κ·Έλ¨μ΄ μκΈ°μΉ μκ² λμ κ°λ₯ν
보μμ½μ | import numpy as np
def handle_data(number, pow):
res = np.power(number, pow, dtype=np.int64)
# 64λΉνΈλ₯Ό λμ΄μλ μ«μμ μ§μκ° μ
λ ₯λ κ²½μ° μ€λ²νλ‘μ°κ° λ°μν΄ κ²°κ³Όκ°μ΄ 0μ΄ λλ€
return res | import numpy as np
MAX_NUMBER = np.iinfo(np.int64).max
MIN_NUMBER = np.iinfo(np.int64).min
def handle_data(number, pow):
calculated = number ** pow
# νμ΄μ¬ κΈ°λ³Έ μλ£νμΌλ‘ ν° μλ₯Ό κ³μ°ν ν μ΄λ₯Ό κ²μ¬ν΄ μ€λ²νλ‘μ° νμ§
if calculated > MAX_NUMBER or calculated < MIN_NUMBER:
# μ€λ²νλ‘μ° νμ§ μ λΉμ μ μ’
λ£λ₯Ό λνλ΄λ β1 κ° λ°ν
return β1
res = np.power(number, pow, dtype=np.int64)
return res |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | 보μκΈ°λ₯ κ²°μ μ μ¬μ©λλ λΆμ μ ν μ
λ ₯κ° | 보μκΈ°λ₯(μΈμ¦, κΆνλΆμ¬ λ±) κ²°μ μ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ λ³΄μκΈ°λ₯μ μ°ννλ
보μμ½μ | from django.shortcuts import render
def init_password(request):
# μΏ ν€μμ κΆν μ 보λ₯Ό κ°μ Έ μ¨λ€
role = request.COOKIE['role']
request_id = request.POST.get('user_id', '')
request_mail = request.POST.get('user_email','')
# μΏ ν€μμ κ°μ Έμ¨ κΆνμ΄ κ΄λ¦¬μμΈμ§ λΉκ΅
if role == 'admin':
# μ¬μ©μμ ν¨μ€μλ μ΄κΈ°ν λ° λ©μΌ λ°μ‘ μ²λ¦¬
password_init_and_sendmail(request_id, request_mail)
return render(request, '/success.html')
else:
return render(request, '/failed.html') | from django.shortcuts import render
def init_password(request):
# μΈμ
μμ κΆν μ 보λ₯Ό κ°μ Έμ΄
role = request.session['role']
request_id = request.POST.get('user_id', '')
request_mail = request.POST.get('user_email','')
# μΈμ
μμ κ°μ Έμ¨ κΆνμ΄ κ΄λ¦¬μμΈμ§ λΉκ΅
if role == βadminβ:
# μ¬μ©μμ ν¨μ€μλ μ΄κΈ°ν λ° λ©μΌ λ°μ‘ μ²λ¦¬
password_init_and_sendmail(request_id, request_mail)
return render(request, '/sucess.html')
else:
return render(request, '/failed.html') |
Python | μ
λ ₯λ°μ΄ν° κ²μ¦ λ° νν | ν¬λ§· μ€νΈλ§ μ½μ
| str.formatλ± ν¬λ§· μ€νΈλ§ μ μ΄ν¨μμ κ²μ¦λμ§ μμ μΈλΆ μ
λ ₯κ°μ νμ©νμ¬ λ°μνλ 보μμ½μ * ν¬λ§· μ€νΈλ§: μ
Β·μΆλ ₯μμ νμμ΄λ ννλ₯Ό μ§μ ν΄μ£Όλ λ¬Έμμ΄ | from django.shortcuts import render
AUTHENTICATE_KEY = 'Passw0rd' def make_user_message(request):
user_info = get_user_info(request.POST.get('user_id', ''))
format_string = request.POST.get('msg_format', '')
# λ΄λΆμ λ―Όκ°ν μ λ³΄κ° μΈλΆλ‘ λ
ΈμΆλ μ μλ€.
# μ¬μ©μκ° μ
λ ₯ν λ¬Έμμ΄μ ν¬λ§· λ¬Έμμ΄λ‘ μ¬μ©νκ³ μμ΄ μμ νμ§ μλ€
message = format_string.format(user=user_info)
return render(request, '/user_page.html', {'message':message}) | from django.shortcuts import render
AUTHENTICATE_KEY = 'Passw0rd' def make_user_message(request):
user_info = get_user_info(request.POST.get('user_id', ''))
# μ¬μ©μκ° μ
λ ₯ν λ¬Έμμ΄μ ν¬λ§· λ¬Έμμ΄λ‘ μ¬μ©νμ§ μμ μμ νλ€
message = 'user name is {}'.format(user_info.name)
return render(request, '/user_page.html', {'message':message}) |
Python | 보μκΈ°λ₯ | μ μ ν μΈμ¦ μλ μ€μ κΈ°λ₯ νμ© | μ€μμ 보(κΈμ΅μ 보, κ°μΈμ 보, μΈμ¦μ 보 λ±)λ₯Ό μ μ ν μΈμ¦μμ΄ μ΄λ(λλ λ³κ²½) κ°λ₯ν
보μμ½μ | from django.shortcuts import render
from re import escape
import hashlib
def change_password(request):
new_pwd = request.POST.get('new_password','')
# λ‘κ·ΈμΈν μ¬μ©μ μ 보
user = '%s' % escape(request.session['userid'])
# νμ¬ passwordμ μΌμΉ μ¬λΆλ₯Ό νμΈνμ§ μκ³ μμ ν¨
sha = hashlib.sha256(new_pwd.encode())
update_password_from_db(user, sha.hexdigest())
return render(request, '/success.html') | from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from re import escape
import hashlib
# login_required decoratorλ₯Ό μ¬μ©ν΄ loginλ μ¬μ©μλ§ μ κ·Όνλλ‘ μ²λ¦¬
@login_required
def change_password(request):
new_pwd = request.POST.get('new_password','')
crnt_pwd = request.POST.get('current_password','')
# λ‘κ·ΈμΈν μ¬μ©μ μ 보λ₯Ό μΈμ
μμ κ°μ Έμ¨λ€.
user = '%s' % escape(request.session['userid'])
crnt_h = hashlib.sha256(crnt_pwd.encode())
h_pwd = crnt_h.hexdigest()
# DBμμ κΈ°μ‘΄ μ¬μ©μμ Hashλ ν¨μ€μλ κ°μ Έμ€κΈ°
old_pwd = get_password_from_db(user)
# ν¨μ€μλλ₯Ό λ³κ²½νκΈ° μ μ¬μ©μμ λν μ¬μΈμ¦μ μννλ€.
if old_pwd == h_pwd:
new_h = hashlib.sha256(new_pwd.encode())
update_password_from_db(user, new_h.hexdigest())
return render(request, '/success.html')
else:
return render(request, 'failed.html', {'error': 'ν¨μ€μλκ° μΌμΉνμ§ μμ΅λλ€'}) |
Python | 보μκΈ°λ₯ | λΆμ μ ν μΈκ° | μ€μμμμ μ κ·Όν λ μ μ ν μ μ΄κ° μμ΄ λΉμΈκ°μμ μ κ·Όμ΄ κ°λ₯ν 보μμ½μ | from django.shortcuts import render
from .model import Content
def delete_content(request):
action = request.POST.get('action', '')
content_id = request.POST.get('content_id', '')
# μμ
μμ²μ νλ μ¬μ©μμ κΆν νμΈ μμ΄ deleteλ₯Ό μν
if action is not None and action == "delete":
Content.objects.filter(id=content_id).delete()
return render(request, '/success.html')
else:
return render(request, '/error.html', {'error':'μ κ·Ό κΆνμ΄ μμ΅λλ€.'}) | from django.contrib.auth.decorators import login_required, permission_required
from django.shortcuts import render
from .model import Content
@login_required
# ν΄λΉ κΈ°λ₯μ μνν κΆνμ΄ μλμ§ νμΈ
@permission_required('content.delete', raise_exception=True)
def delete_content(request):
action = request.POST.get('action', '')
content_id = request.POST.get('content_id', '')
if action is not None and action == "delete":
Content.objects.filter(id=content_id).delete()
return render(request, '/success.html')
else:
return render(request, '/error.html', {'error':'μμ μ€ν¨'}) |
Python | 보μκΈ°λ₯ | μ€μν μμμ λν μλͺ»λ κΆν μ€μ | μ€μμμμ μ μ ν μ κ·Ό κΆνμ λΆμ¬νμ§ μμ μ€μμ λ³΄κ° λ
ΈμΆΒ·μμ κ°λ₯ν 보μμ½μ | import os
def write_file():
# λͺ¨λ μ¬μ©μκ° μ½κΈ°, μ°κΈ°, μ€ν κΆνμ κ°μ§κ² λλ€.
os.chmod('/root/system_config', 0o777)
with open("/root/system_config", 'w') as f:
f.write("your config is broken") | import os
def write_file():
# μμ μ μΈμλ μλ¬΄λ° κΆνμ μ£Όμ§ μμ.
os.chmod('/root/system_config', 0o700)
with open("/root/system_config", β'w') as f:
f.write("your config is broken") |
Python | 보μκΈ°λ₯ | μ·¨μ½ν μνΈν μκ³ λ¦¬μ¦ μ¬μ© | μ€μμ 보 (κΈμ΅μ 보, κ°μΈμ 보, μΈμ¦μ 보 λ±)μ κΈ°λ°μ±μ 보μ₯ν μ μλ μ·¨μ½ν μνΈν μκ³ λ¦¬μ¦μ μ¬μ©νμ¬ μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | import base64
from Crypto.Cipher import DES
from Crypto.Util.Padding import pad
def get_enc_text(plain_text, key):
# μ·¨μ½ν¨ μνΈν μκ³ λ¦¬μ¦μΈ DESλ₯Ό μ¬μ©νμ¬ μμ νμ§ μμ
cipher_des = DES.new(key, DES.MODE_ECB)
encrypted_data = base64.b64encode(cipher_aes.encrypt(pad(plain_text, 32)))
return encrypted_data.decode('ASCII') | import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
def get_enc_text(plain_text, key, iv):
# μμ ν μκ³ λ¦¬μ¦μΈ AES λ₯Ό μ¬μ©νμ¬ μμ ν¨.
cipher_aes = AES.new(key, AES.MODE_CBC, iv)
encrypted_data = base64.b64encode(cipher_aes.encrypt(pad(plain_text, 32)))
return encrypted_data.decode('ASCII') |
Python | 보μκΈ°λ₯ | μ·¨μ½ν μνΈν μκ³ λ¦¬μ¦ μ¬μ© | μ€μμ 보 (κΈμ΅μ 보, κ°μΈμ 보, μΈμ¦μ 보 λ±)μ κΈ°λ°μ±μ 보μ₯ν μ μλ μ·¨μ½ν μνΈν μκ³ λ¦¬μ¦μ μ¬μ©νμ¬ μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | import hashlib
def make_md5(plain_text):
# μ·¨μ½ν md5 ν΄μν¨μ μ¬μ©
hash_text = hashlib.md5(plain_text.encode('utf-8')).hexdigest()
return hash_text | import hashlib
def make_sha256(plain_text):
# μμ ν sha-256 ν΄μν¨μ μ¬μ©
hash_text = hashlib.sha256(plain_text.encode('utf-8')).hexdigest()
return hash_text |
Python | 보μκΈ°λ₯ | μνΈνλμ§ μμ μ€μμ 보 | μ€μμ 보(ν¨μ€μλ, κ°μΈμ 보 λ±) μ μ‘ μ μνΈν λλ μμ ν ν΅μ μ±λμ μ΄μ©νμ§ μκ±°λ, μ μ₯ μ μνΈν νμ§ μμ μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | def update_pass(dbconn, password, user_id):
curs = dbconn.cursor()
# μνΈνλμ§ μμ ν¨μ€μλλ₯Ό DBμ μ μ₯
curs.execute(
'UPDATE USERS SET PASSWORD=%s WHERE USER_ID=%s',
password,
user_id
)
dbconn.commit() | from Crypto.Hash import SHA256
def update_pass(dbconn, password, user_id, salt):
# λ¨λ°©ν₯ μνΈνλ₯Ό μ΄μ©νμ¬ ν¨μ€μλλ₯Ό μνΈν
hash_obj = SHA256.new()
hash_obj.update(bytes(password + salt, 'utf-8'))
hash_pwd = hash_obj.hexdigest()
curs = dbconn.cursor()
curs.execute(
'UPDATE USERS SET PASSWORD=%s WHERE USER_ID=%s',
(hash_pwd, user_id)
)
dbconn.commit() |
Python | 보μκΈ°λ₯ | μνΈνλμ§ μμ μ€μμ 보 | μ€μμ 보(ν¨μ€μλ, κ°μΈμ 보 λ±) μ μ‘ μ μνΈν λλ μμ ν ν΅μ μ±λμ μ΄μ©νμ§ μκ±°λ, μ μ₯ μ μνΈν νμ§ μμ μ λ³΄κ° λ
ΈμΆ κ°λ₯ν 보μμ½μ | import socket
HOST = '127.0.0.1'
PORT = 65434
def send_password(password):
......
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
# ν¨μ€μλλ₯Ό μνΈν νμ§ μκ³ μ μ‘νμ¬ μμ νμ§ μλ€.
s.sendall(password.encode('utf-8'))
data = s.recv(1024)
....... | import socket
import os
from Crypto.Cipher import AES
HOST = '127.0.0.1'
PORT = 65434
def send_password(password):
# λ¬Έμμ΄λ‘ μ μ₯λμ΄ μλ λΈλ‘ν€λ₯Ό λ‘λ
block_key = os.environ.get('BLOCK_KEY')
aes = AEScipher(block_key)
# ν¨μ€μλ λ± μ€μ μ 보λ μνΈννμ¬ μ μ‘νλ κ²μ΄ μμ νλ€
enc_passowrd = aes.encrypt(passowrd)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(enc_passowrd.encode('utf-8'))
data = s.recv(1024)
.......
class AEScipher:
BS = AES.block_size
def __init__(self, s_key):
self.s_key = hashlib.sha256(s_key.encode("utf-8")).digest()
def pad(self, m):
return m + bytes([self.BS - len(m) % self.BS] * (self.BS - len(m) % self.BS))
def encrypt(self, plain):
plain = self.pad(plain.encode())
iv = Random.new().read(AES.block_size)
cipher = AES.new(self.s_key, AES.MODE_CBC, iv)
return base64.b64encode(iv + cipher.encrypt(plain)).decode("utf-8")
....... |
Python | 보μκΈ°λ₯ | νλμ½λλ μ€μμ 보 | μμ€μ½λμ μ€μμ 보(ν¨μ€μλ, μνΈνν€ λ±)λ₯Ό μ§μ μ½λ©νμ¬ μμ€μ½λ μ μΆ μ μ€μμ 보κ°λ
ΈμΆλκ³ μ£ΌκΈ°μ λ³κ²½μ΄ μ΄λ €μ΄ 보μμ½μ | import pymysql
def query_execute(query):
# user, passwdκ° μμ€μ½λμ νλ¬ΈμΌλ‘ νλμ½λ©λμ΄ μμ
dbconn = pymysql.connect(
host='127.0.0.1',
port='1234',
user='root',
passwd='1234',
db='mydb',
charset='utf8',
)
curs = dbconn.cursor()
curs.execute(query)
dbconn.commit()
dbconn.close() | import pymysql
import json
def query_execute(query, config_path): with open(config_path, 'r') as config:
# μ€μ νμΌμμ user, passwdλ₯Ό κ°μ Έμ μ¬μ©
dbconf = json.load(fp=config)
# μνΈνλμ΄ μλ λΈλ‘ μνΈν ν€λ₯Ό 볡νΈν ν΄μ κ°μ Έμ€λ
# μ¬μ©μ μ μ ν¨μ
blockKey = get_decrypt_key(dbconf['blockKey'])
# μ€μ νμΌμ μνΈνλμ΄ μλ κ°μ κ°μ Έμ 볡νΈνν νμ μ¬μ©
dbUser = decrypt(blockKey, dbconf['user']) dbPasswd = decrypt(blockKey, dbconf['passwd'])
dbconn = pymysql.connect(
host=dbconf['host']
port=dbconf['port'],
user=dbUser,
passwd=dbPasswd,
db=dbconf['db_name'],
charset='utf8',
)
curs = dbconn.cursor()
curs.execute(query)
dbconn.commit()
dbconn.close() |
Python | 보μκΈ°λ₯ | μΆ©λΆνμ§ μμ ν€ κΈΈμ΄ μ¬μ© | μνΈν λ±μ μ¬μ©λλ ν€μ κΈΈμ΄κ° μΆ©λΆνμ§ μμ λ°μ΄ν°μ κΈ°λ°μ±Β·λ¬΄κ²°μ±μ 보μ₯ν μ μλ보μμ½μ | from Crypto.PublicKey import RSA, DSA, ECC
from tinyec import registry
import secrets
def make_rsa_key_pair():
# RSAν€ κΈΈμ΄λ₯Ό 2048 λΉνΈ μ΄νλ‘ μ€μ νλ κ²½μ° μμ νμ§ μμ
private_key = RSA.generate(1024)
public_key = private_key.publickey()
def make_ecc():
# ECCμ ν€ κΈΈμ΄λ₯Ό 224λΉνΈ μ΄νλ‘ μ€μ νλ κ²½μ° μμ νμ§ μμ
ecc_curve = registry.get_curve('secp192r1')
private_key = secrets.randbelow(ecc_curve.field.n)
public_key = private_key * ecc_curve.g | from Crypto.PublicKey import RSA, DSA, ECC
from tinyec import registry
import secrets
def make_rsa_key_pair():
# RSA ν€ κΈΈμ΄λ₯Ό 2048 λΉνΈ μ΄μμΌλ‘ κΈΈκ² μ€μ
private_key = RSA.generate(2048)
public_key = private_key.publickey()
def make_ecc():
# ECC ν€ κΈΈμ΄λ₯Ό 224 λΉνΈ μ΄μμΌλ‘ μ€μ
ecc_curve = registry.get_curve('secp224r1')
private_key = secrets.randbelow(ecc_curve.field.n)
public_key = private_key * ecc_curve.g |
Python | 보μκΈ°λ₯ | μ μ νμ§ μμ λμ κ° μ¬μ© | μ¬μ©ν λμκ° μμΈ‘ κ°λ₯νμ¬, 곡격μκ° λ€μ λμλ₯Ό μμν΄μ μμ€ν
μ 곡격 κ°λ₯ν 보μμ½μ | import random
def get_otp_number():
random_str = '' # μμ€ν
νμ¬ μκ° κ°μ μλλ‘ μ¬μ©νκ³ μμΌλ©°, μ£Όμ 보μ κΈ°λ₯μ μν
# λμλ‘ μμ νμ§ μλ€
for i in range(6):
random_str += str(random.randrange(10))
return random_str | import secrets
def get_otp_number():
random_str = ''
# 보μκΈ°λ₯μ μ ν©ν λμ μμ±μ© secrets λΌμ΄λΈλ¬λ¦¬ μ¬μ©
for i in range(6):
random_str += str(secrets.randbelow(10))
return random_str |
Python | 보μκΈ°λ₯ | μ μ νμ§ μμ λμ κ° μ¬μ© | μ¬μ©ν λμκ° μμΈ‘ κ°λ₯νμ¬, 곡격μκ° λ€μ λμλ₯Ό μμν΄μ μμ€ν
μ 곡격 κ°λ₯ν 보μμ½μ | import random
import string
def generate_session_key():
RANDOM_STRING_CHARS = string.ascii_letters + string.digits
# random λΌμ΄λΈλ¬λ¦¬λ₯Ό 보μ κΈ°λ₯μ μ¬μ©νλ©΄ μννλ€
return ββ.join(random.choice(RANDOM_STRING_CHARS) for i in range(32)) | import secrets
import string
def generate_session_key():
RANDOM_STRING_CHARS = string.ascii_letters+string.digits
# 보μ κΈ°λ₯κ³Ό κ΄λ ¨λ λμλ secrets λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©ν΄μΌ μμ νλ€
return ββ.join(secrets.choice(RANDOM_STRING_CHARS) for i in range(32)) |
Python | 보μκΈ°λ₯ | μ·¨μ½ν ν¨μ€μλ νμ© | ν¨μ€μλ μ‘°ν©κ·μΉ(μλ¬Έ, μ«μ, νΉμλ¬Έμ λ±) λ―Έν‘ λ° κΈΈμ΄κ° μΆ©λΆνμ§ μμ ν¨μ€μλκ°
λ
ΈμΆ κ°λ₯ν 보μμ½μ | from flask import request, redirect
from Models import User
from Models import db
@app.route('/register', methods=['POST'])
def register():
userid = request.form.get('userid')
password = request.form.get('password')
confirm_password = request.form.get('confirm_password')
if password != confirm_password:
return make_response("ν¨μ€μλκ° μΌμΉνμ§ μμ΅λλ€", 400)
else:
usertable = User()
usertable.userid = userid
usertable.password = password
# ν¨μ€μλ μμ± κ·μΉμ νμΈνμ§ μκ³ νμ κ°μ
db.session.add(usertable)
db.session.commit()
return make_response("νμκ°μ
μ±κ³΅", 200) | from flask import request, redirect
from Models import User
from Models import db
import re
@app.route('/register', methods=['POST'])
def register():
userid = request.form.get('userid')
password = request.form.get('password')
confirm_password = request.form.get('confirm_password')
if password != confirm_password:
return make_response("ν¨μ€μλκ° μΌμΉνμ§ μμ΅λλ€.", 400)
if not check_password(password):
return make_response("ν¨μ€μλ μ‘°ν©κ·μΉμ λ§μ§ μμ΅λλ€.", 400)
else:
usertable = User()
usertable.userid = userid
usertable.password = password
db.session.add(usertable)
db.session.commit()
return make_response("νμκ°μ
μ±κ³΅", 200)
def check_password(password):
# 3μ’
μ΄μ λ¬Έμλ‘ κ΅¬μ±λ 8μ리 μ΄μ ν¨μ€μλ κ²μ¬ μ κ·μ μ μ©
PT1 = re.compile('^(?=.*[A-Z])(?=.*[a-z])[A-Za-z\d!@#$%^&*]{8,}$')
PT2 = re.compile('^(?=.*[A-Z])(?=.*\d)[A-Za-z\d!@#$%^&*]{8,}$')
PT3 = re.compile('^(?=.*[A-Z])(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$')
PT4 = re.compile('^(?=.*[a-z])(?=.*\d)[A-Za-z\d!@#$%^&*]{8,}$')
PT5 = re.compile('^(?=.*[a-z])(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$')
PT6 = re.compile('^(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$')
# λ¬Έμ κ΅¬μ± μκ΄μμ΄ 10μ리 μ΄μ ν¨μ€μλ κ²μ¬ μ κ·μ
PT7 = re.compile('^[A-Za-z\d!@#$%^&*]{10,}$')
for pattern in [PT1, PT2, PT3, PT4, PT5, PT6, PT7]:
if pattern.match(password):
return True
return False |
Python | 보μκΈ°λ₯ | μ·¨μ½ν ν¨μ€μλ νμ© | ν¨μ€μλ μ‘°ν©κ·μΉ(μλ¬Έ, μ«μ, νΉμλ¬Έμ λ±) λ―Έν‘ λ° κΈΈμ΄κ° μΆ©λΆνμ§ μμ ν¨μ€μλκ°
λ
ΈμΆ κ°λ₯ν 보μμ½μ | from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import User
from django.views.decorators.http import require_POST
@require_POST
def register(request):
userid = request.POST.get('userid')
password = request.POST.get('password')
confirm_password = request.POST.get('confirm_password')
if password != confirm_password:
return HttpResponse("ν¨μ€μλκ° μΌμΉνμ§ μμ΅λλ€", status=400)
else:
usertable = User()
usertable.userid = userid
usertable.password = password
# ν¨μ€μλ μμ± κ·μΉμ νμΈνμ§ μκ³ νμ κ°μ
usertable.save()
return HttpResponse("νμκ°μ
μ±κ³΅", status=200) | import re
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _ class CustomValidator(object):
def validate(self, password, user=None):
# 3μ’
μ΄μ λ¬Έμλ‘ κ΅¬μ±λ 8μ리 μ΄μ ν¨μ€μλ κ²μ¬ μ κ·μ
PT1 = re.compile('^(?=.*[A-Z])(?=.*[a-z])[A-Za-z\d!@#$%^&*]{8,}$')
PT2 = re.compile('^(?=.*[A-Z])(?=.*\d)[A-Za-z\d$@$!%*?&]{8,}$')
PT3 = re.compile('^(?=.*[A-Z])(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$')
PT4 = re.compile('^(?=.*[a-z])(?=.*\d)[A-Za-z\d!@#$%^&*]{8,}$')
PT5 = re.compile('^(?=.*[a-z])(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$')
PT6 = re.compile('^(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$')
# λ¬Έμ κ΅¬μ± μκ΄μμ΄ 10μ리 μ΄μ ν¨μ€μλ κ²μ¬ μ κ·μ
PT7 = re.compile('^[A-Za-z\d!@#$%^&*]{10,}$')
for pattern in [PT1, PT2, PT3, PT4, PT5, PT6, PT7]:
if pattern.match(password):
return None
raise ValidationError(
_("ν¨μ€μλ μ‘°ν©κ·μΉμ μ ν©νμ§ μμ΅λλ€.."),
code='improper_password',
)
def get_help_text(self):
return _(
"ν¨μ€μλλ μλ¬Έ λλ¬Έμ, μλ¬Έμ, μ«μ, νΉμλ¬Έμ μ‘°ν© μ€ 2κ°μ§ μ΄μ 8μ리μ΄κ±°λ λ¬Έμ ꡬμ±
μκ΄μμ΄ 10μ리 μ΄μμ΄μ΄μΌ ν©λλ€."
) |
Python | 보μκΈ°λ₯ | λΆμ μ ν μ μμλͺ
νμΈ | νλ‘κ·Έλ¨, λΌμ΄λΈλ¬λ¦¬, μ½λμ μ μμλͺ
μ λν μ ν¨μ± κ²μ¦μ΄ μ μ νμ§ μμ 곡격μμ
μ
μμ μΈ μ½λκ° μ€ν κ°λ₯ν 보μμ½μ | import base64
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA256
from Crypto.Signature import PKCS1_v1_5 as SIGNATURE_PKCS1_v1_5
from Crypto.Cipher import PKCS1_v1_5, AES
from Crypto.Util.Padding import unpad
... def verify_data(request):
# ν΄λΌμ΄μΈνΈλ‘λΆν° μ λ¬λ°μ λ°μ΄ν°(μ μμλͺ
μ μμ μ²λ¦¬ νμ§ μμ)
encrypted_code = request.POST.get("encrypted_msg", "") # μνΈνλ νμ΄μ¬ μ½λ
# μλ²μ λμΉν€ λ‘λ (μ‘μμ μΈ‘μ΄ λμΉν€λ₯Ό μ΄λ―Έ 곡μ νλ€κ³ κ°μ )
with open(f"{PATH}/keys/secret_key.out", "rb") as f:
secret_key = f.read()
# λμΉν€λ‘ ν΄λΌμ΄μΈνΈκ° μ λ¬ν νμ΄μ¬ μ½λ 볡νΈν
# (decrypt_with_symmetric_key ν¨μλ μμμ ν¨μλͺ
μΌλ‘ μΈλΆμ μΈ λ³΅νΈν κ³Όμ μ μλ΅ν¨)
origin_python_code = decrypt_with_symmetric_key(secret_key, encrypted_code)
# ν΄λΌμ΄μΈνΈλ‘λΆν° μ λ¬ λ°μ νμ΄μ¬ μ½λ μ€ν
eval(origin_python_code)
return render(
request,
"/verify_success.html",
{"result": "νμ΄μ¬ μ½λλ₯Ό μ€ννμ΅λλ€."},
) | # μ μμλͺ
κ²μ¦μ μ¬μ©ν μ½λλ μμ‘΄ν νμ΄μ¬ ν¨ν€μ§ λ° μ‘μ μΈ‘ μΈμ΄μ λ°λΌ
# λ¬λΌμ§ μ μμΌλ©°, μ¬μ μ 곡μ ν 곡κ°ν€λ‘ 볡νΈνν μ μμλͺ
κ³Ό μλ³Έ λ°μ΄ν° ν΄μκ°μ
# μΌμΉ μ¬λΆλ₯Ό κ²μ¬νλ μ½λλ₯Ό ν¬ν¨
def verify_digit_signature (
origin_data: bytes, origin_signature: bytes, client_pub_key: str ) -> bool:
hashed_data = SHA256.new(origin_data)
signer = SIGNATURE_PKCS1_v1_5.new(RSA.importKey(client_pub_key))
return signer.verify(hashed_data, base64.b64decode(origin_signature))
def verify_data(request):
# ν΄λΌμ΄μΈνΈλ‘λΆν° μ λ¬λ°μ λ°μ΄ν°
encrypted_code = request.POST.get("encrypted_msg", "") # μνΈνλ νμ΄μ¬ μ½λ
encrypted_sig = request.POST.get("encrypted_sig", "") # μνΈνλ μ μμλͺ
# μλ²μ λμΉ(λΉλ°)ν€ λ° κ³΅κ°ν€ λ‘λ
with open(f"/keys/secret_key.out", "rb") as f:
secret_key = f.read()
with open(f"/keys/public_key.out", "rb") as f:
public_key = f.read()
# λμΉν€λ‘ νμ΄μ¬ μ½λ λ° μ μμλͺ
볡νΈν
origin_python_code = decrypt_with_symmetric_key(symmetric_key, encrypted_code)
origin_signature = decrypt_with_symmetric_key(symmetric_key, encrypted_sig)
# ν΄λΌμ΄μΈνΈμ 곡κ°ν€λ₯Ό ν΅ν΄ νμ΄μ¬ μ½λ(μλ¬Έ)μ μ μμλͺ
μ κ²μ¦
verify_result = verify_digit_signature(origin_python_code, origin_signature, client_pub_key)
# μ μμλͺ
κ²μ¦μ ν΅κ³Όνλ€λ©΄ νμ΄μ¬ μ½λ μ€ν
if verify_result:
eval(origin_python_code)
return render(request, "/verify_success.html",
{"result": "μ μμλͺ
κ²μ¦ ν΅κ³Ό λ° νμ΄μ¬ μ½λλ₯Ό μ€ννμ΅λλ€."},
)
else:
return render(request, "/verify_failed.html",
{"result": "μ μμλͺ
λλ νμ΄μ¬ μ½λκ° μ/λ³μ‘°λμμ΅λλ€."},
) |
Python | 보μκΈ°λ₯ | λΆμ μ ν μΈμ¦μ μ ν¨μ± κ²μ¦ | μΈμ¦μμ λν μ ν¨μ± κ²μ¦μ΄ μ μ νμ§ μμ λ°μνλ 보μμ½μ | import os
import socket
import ssl
HOST, PORT = "127.0.0.1", 7917
def connect_with_server():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) as sock:
# 보μ μ μ±
μλ μ€μ
context = ssl.SSLContext()
# SSLContext μμ±μλ₯Ό μ§μ νΈμΆν λ, CERT_NONEμ΄ κΈ°λ³Έκ°
# μλλ°©μ μΈμ¦νμ§ μκΈ° λλ¬Έμ ν΅μ νκ³ μνλ μλ²μ μ λ’°μ±μ 보μ₯ν μ μμ
context.verify_mode = ssl.CERT_NONE
with context.wrap_socket(sock) as ssock:
try:
ssock.connect((HOST, PORT))
ssock.send("Hello I'm a vulnerable client :)".encode("utf-8"))
data = ssock.recv(1024).decode("utf-8")
print(f">> server from ({HOST}, {PORT}): {data}\n")
finally:
ssock.close() | import os
import socket
import ssl
CURRENT_PATH = os.getcwd()
HOST_NAME = "test-server"
HOST, PORT = "127.0.0.1", 7917
SERVER_CA_PEM = f"{CURRENT_PATH}/rsa_server/CA.pem" # μλ²λ‘λΆν° μ λ¬λ°μ CA μΈμ¦μ
def connect_with_server():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) as sock:
# PROTOCOL_TLS_CLIENT νλ‘ν μ½μ μΆκ°νμ¬ μΈμ¦μ μ ν¨μ± κ²μ¬μ νΈμ€νΈ μ΄λ¦ νμΈμ μν
# contextλ₯Ό ꡬμ±. verify_modeκ° CERT_REQUIREDλ‘ μ€μ λ¨
# check_hostnameμ΄ Trueλ‘ μ€μ λ¨
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
# μλ²λ‘λΆν° μ λ¬λ°μ CA μΈμ¦μλ₯Ό contextμ λ‘λ
# CERT_REQUIREDλ‘ μΈν΄ νμ
context.load_verify_locations(SERVER_CA_PEM)
# νΈμ€νΈ μ΄λ¦(HOST_NAME)μ΄ μΌμΉνμ§ μμΌλ©΄ ν΅μ λΆκ°
# μμ±λ μμΌκ³Ό context wrapping μ server_hostnameμ΄ μ€μ μλ²μμ
# λ±λ‘(server.csr)ν νΈμ€νΈ λͺ
κ³Ό μΌμΉν΄μΌ ν¨
with context.wrap_socket(sock, server_hostname=HOST_NAME) as ssock:
try:
ssock.connect((HOST, PORT))
ssock.send("Hello I'm a patched client :)".encode("utf-8"))
data = ssock.recv(1024).decode("utf-8")
print(f">> server from ({HOST}, {PORT}): {data}\n")
finally:
ssock.close() |
Python | 보μκΈ°λ₯ | μ¬μ©μ νλλμ€ν¬μ μ μ₯λλ μΏ ν€λ₯Ό ν΅ν μ 보 λ
ΈμΆ | μΏ ν€(μΈμ
ID, μ¬μ©μ κΆνμ 보 λ± μ€μμ 보)λ₯Ό μ¬μ©μ νλλμ€ν¬μ μ μ₯νμ¬ μ€μμ 보κ°
λ
ΈμΆ κ°λ₯ν 보μμ½μ | from django.http import HttpResponse
def remind_user_state(request):
res = HttpResponse()
# μΏ ν€μ λ§λ£μκ°μ 1λ
μΌλ‘ κ³Όλνκ² κΈΈκ² μ€μ νκ³ μμ΄ μμ νμ§ μλ€
res.set_cookie('rememberme', 1, max_age=60*60*24*365)
return res | from django.http import HttpResponse
def remind_user_state(request):
res = HttpResponse()
# μΏ ν€μ λ§λ£μκ°μ μ μ νκ² λΆμ¬νκ³ secure λ° httpOnly μ΅μ
μ νμ±ν νλ€.
res.set_cookie('rememberme', 1, max_age=60*60, secure=True, httponly=True)
return res |
Python | 보μκΈ°λ₯ | μ¬μ©μ νλλμ€ν¬μ μ μ₯λλ μΏ ν€λ₯Ό ν΅ν μ 보 λ
ΈμΆ | μΏ ν€(μΈμ
ID, μ¬μ©μ κΆνμ 보 λ± μ€μμ 보)λ₯Ό μ¬μ©μ νλλμ€ν¬μ μ μ₯νμ¬ μ€μμ 보κ°
λ
ΈμΆ κ°λ₯ν 보μμ½μ | from django.http import HttpResponse
def remind_user_state(request):
res = HttpResponse()
# μΏ ν€μ λ§λ£μκ°μ 1λ
μΌλ‘ κ³Όλνκ² κΈΈκ² μ€μ νκ³ μμ΄ μμ νμ§ μλ€
res.set_cookie('rememberme', 1, max_age=60*60*24*366)
return res | from django.http import HttpResponse
from django.conf.global_settings import (
SESSION_COOKIE_AGE,
SESSION_COOKIE_HTTPONLY,
SESSION_COOKIE_HTTPONLY,
)
""" # settings.py
SESSION_COOKIE_AGE = 60 * 60 * 24 * 14
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SECURE = True
""" def remind_user_state(request):
res = HttpResponse()
# μλ² μΈν
(setting.py)μμ defaultλ‘ μΏ ν€ μ΅μ
μ μ€μ ν μν
res.set_cookie(
"rememerme",
1,
max_age=SESSION_COOKIE_AGE,
secure=SESSION_COOKIE_HTTPONLY,
httponly=SESSION_COOKIE_HTTPONLY,
)
return res |
End of preview. Expand
in Dataset Viewer.
No dataset card yet
- Downloads last month
- 36