NJSSCAN은 LibSast 및 구문 인식 시맨틱 코드 패턴 검색 도구 Semgrep의 간단한 패턴 매칭을 사용하여 Node.js 애플리케이션에서 불안정한 코드 패턴을 찾을 수있는 정적 응용 프로그램 테스트 (SAST) 도구입니다.
만들어졌습니다


opsecx node.js 보안 : Pentesting and Exploitation -NJS
pip install njsscan
Python 3.7+가 필요하며 Mac 및 Linux 만 지원합니다
$ njsscan
usage: njsscan [-h] [--json] [--sarif] [--sonarqube] [--html] [-o OUTPUT] [-c CONFIG] [--missing-controls] [-w] [-v] [path ...]
positional arguments:
path Path can be file(s) or directories with source code
optional arguments:
-h, --help show this help message and exit
--json set output format as JSON
--sarif set output format as SARIF 2.1.0
--sonarqube set output format compatible with SonarQube
--html set output format as HTML
-o OUTPUT, --output OUTPUT
output filename to save the result
-c CONFIG, --config CONFIG
Location to .njsscan config file
--missing-controls enable missing security controls check
-w, --exit-warning non zero exit code on warning
-v, --version show njsscan version$ njsscan test.js
- Pattern Match ████████████████████████████████████████████████████████████ 1
- Semantic Grep ███████████████████████████ 160
njsscan: v0.1.9 | Ajin Abraham | opensecurity.in
╒═════════════╤═══════════════════════════════════════════════════════════════════════════════════════════════╕
│ RULE ID │ express_xss │
├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ OWASP │ A1: Injection │
├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ CWE │ CWE-79: Improper Neutralization of Input During Web Page Generation ( ' Cross-site Scripting ' ) │
├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ DESCRIPTION │ Untrusted User Input in Response will result in Reflected Cross Site Scripting Vulnerability. │
├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ SEVERITY │ ERROR │
├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────┤
│ FILES │ ╒════════════════╤═══════════════════════════════════════════════╕ │
│ │ │ File │ test.js │ │
│ │ ├────────────────┼───────────────────────────────────────────────┤ │
│ │ │ Match Position │ 5 - 46 │ │
│ │ ├────────────────┼───────────────────────────────────────────────┤ │
│ │ │ Line Number(s) │ 7: 8 │ │
│ │ ├────────────────┼───────────────────────────────────────────────┤ │
│ │ │ Match String │ const { name } = req.query ; │ │
│ │ │ │ res.send( ' <h1> Hello : ' + name + " </h1> " ) │ │
│ │ ╘════════════════╧═══════════════════════════════════════════════╛ │
╘═════════════╧═══════════════════════════════════════════════════════════════════════════════════════════════╛NJSSCAN 위에 구축 된 NodeJSSCAN 은 기타 Nifty 통합과 함께 완전한 연약한 취약성 관리 사용자 인터페이스를 제공합니다.

nodejsscan을 참조하십시오
> >> from njsscan . njsscan import NJSScan
> >> node_source = '/node_source/true_positives/sqli_node.js'
> >> scanner = NJSScan ([ node_source ], json = True , check_controls = False )
> >> scanner . scan ()
{
'templates' : {},
'nodejs' : {
'node_sqli_injection' : {
'files' : [{
'file_path' : '/node_source/true_positives/sqli_node.js' ,
'match_position' : ( 1 , 24 ),
'match_lines' : ( 4 , 11 ),
'match_string' : 'var employeeId = req.foo; n n var sql = "SELECT * FROM trn_employee WHERE employee_id = " + employeeId; n n n n connection.query(sql, function (error, results, fields) { n n if (error) { n n throw error; n n } n n console.log(results);'
}],
'metadata' : {
'owasp' : 'A1: Injection' ,
'cwe' : "CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')" ,
'description' : 'Untrusted input concatinated with raw SQL query can result in SQL Injection.' ,
'severity' : 'ERROR'
}
}
},
'errors' : []
} 소스 코드 디렉토리의 루트에있는 .njsscan 파일을 사용하면 njsscan을 구성 할 수 있습니다. --config 인수를 사용하여 사용자 정의 .njsscan 파일을 사용할 수도 있습니다.
---
- nodejs-extensions :
- .js
template-extensions :
- .new
- .hbs
- ' '
ignore-filenames :
- skip.js
ignore-paths :
- __MACOSX
- skip_dir
- node_modules
ignore-extensions :
- .jsx
ignore-rules :
- regex_injection_dos
- pug_jade_template
severity-filter :
- WARNING
- ERROR 주석 // njsscan-ignore: rule_id1, rule_id2 결과를 트리거하는 줄에 추가하여 JavaScript 소스 파일의 결과를 억제 할 수 있습니다.
예:
app . get ( '/some/redirect' , function ( req , res ) {
var target = req . param ( "target" ) ;
res . redirect ( target ) ; // njsscan-ignore: express_open_redirect
} ) ; CI/CD 또는 DevSecops 파이프 라인에서 NJSSCAN을 활성화 할 수 있습니다.
.github/workflows/njsscan.yml 파일에 다음을 추가하십시오.
name : njsscan
on :
push :
branches : [ master, main ]
pull_request :
branches : [ master, main ]
jobs :
njsscan :
runs-on : ubuntu-latest
name : njsscan check
steps :
- name : Checkout the code
uses : actions/[email protected]
- uses : actions/[email protected]
with :
python-version : ' 3.12 '
- name : nodejsscan scan
id : njsscan
uses : ajinabraham/njsscan-action@master
with :
args : ' . '예 : njsscan github 동작을 갖는 dvna
.github/workflows/njsscan_sarif.yml 파일에 다음을 추가하십시오.
name : njsscan sarif
on :
push :
branches : [ master, main ]
pull_request :
branches : [ master, main ]
jobs :
njsscan :
runs-on : ubuntu-latest
name : njsscan code scanning
steps :
- name : Checkout the code
uses : actions/[email protected]
- uses : actions/[email protected]
with :
python-version : ' 3.12 '
- name : nodejsscan scan
id : njsscan
uses : ajinabraham/njsscan-action@master
with :
args : ' . --sarif --output results.sarif || true '
- name : Upload njsscan report
uses : github/codeql-action/upload-sarif@v3
with :
sarif_file : results.sarif 
파일 .gitlab-ci.yml 에 다음을 추가하십시오.
stages :
- test
njsscan :
image : python
before_script :
- pip3 install --upgrade njsscan
script :
- njsscan .예 : njsscan gitlab을 사용한 DVNA
다음을 파일 .travis.yml 에 추가하십시오.
language : python
install :
- pip3 install --upgrade njsscan
script :
- njsscan . 다음을 파일 .circleci/config.yaml 에 추가하십시오
version : 2.1
jobs :
njsscan :
docker :
- image : cimg/python:3.9.6
steps :
- checkout
- run :
name : Install njsscan
command : pip install --upgrade njsscan
- run :
name : njsscan check
command : njsscan . docker pull opensecurity/njsscan
docker run -v /path-to-source-dir:/src opensecurity/njsscan /src docker build -t njsscan .
docker run -v /path-to-source-dir:/src njsscan /src