├── README.md ├── flaskapp.py ├── sastgrep.py ├── static └── logo_sast.png └── templates ├── demo.html ├── index.html └── uf.html /README.md: -------------------------------------------------------------------------------- 1 | # sastgriper 2 | A simple grep user interface for searching code which can be used for SAST. 3 | 4 | Before you start reading this I want to make sure the whole project is based upon this grep command. 5 | 6 | grep -irnE “regexp” ./pathtoFolder. 7 | 8 | I haven’t done anything new or I m not even bragging. I m starting and posting this for feedbacks and features which are going to be added in the upcoming versions. Feel free to give any suggestions, feedback. 9 | I have only added a user interface where you can click a button which is mentioning your desired file and a visual studio code’s window will be opened and the cursor will directly point to that line number. You can add a breakpoint directly to the line number it in visual studio code. 10 | 11 | # Requirements 12 | 13 | 1.Flask Must be installed. 14 | 15 | 2.Make sure you have visual studio code installed on your system and 'code' command for visual studio code must be configured with your environment. 16 | 17 | # WriteUp 18 | 19 | https://mohitdabas.wordpress.com/2019/09/20/sastgriper-finding-vulnerable-code-via-grep/ 20 | -------------------------------------------------------------------------------- /flaskapp.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,render_template,jsonify,request,json 2 | import sastgrep 3 | import os 4 | import pickle 5 | app=Flask(__name__) 6 | 7 | FolderMark='' 8 | 9 | @app.route('/') 10 | def index_page(): 11 | return render_template('index.html') 12 | 13 | @app.route('/demo') 14 | def demo(): 15 | return render_template('demo.html') 16 | 17 | @app.route('/uf') 18 | def uf(): 19 | return render_template('uf.html') 20 | 21 | 22 | @app.route('/folder_mark',methods=['GET','POST']) 23 | def folder_mark(): 24 | global FolderMark 25 | FolderMark=request.form['FolderMarked'] 26 | FileObject=open("fm",'wb') 27 | pickle.dump(FolderMark,FileObject) 28 | FileObject.close() 29 | return jsonify(FolderMark) 30 | 31 | @app.route('/get_regex',methods=['GET','POST']) 32 | def get_regex(): 33 | RegExp=request.form['Regexp'] 34 | FileObject=open("fm",'rb') 35 | FolderMark=pickle.load(FileObject) 36 | print(FolderMark) 37 | Data=sastgrep.command_rec(RegExp,FolderMark) 38 | return jsonify(Data) 39 | 40 | @app.route('/open_viscode',methods=['GET','POST']) 41 | def open_viscode(): 42 | PathNLineNum=request.form['PathNLineNum'] 43 | os.system("code -g "+PathNLineNum) 44 | return jsonify(PathNLineNum) 45 | 46 | 47 | if __name__=='__main__': 48 | app.run(debug=True) 49 | 50 | -------------------------------------------------------------------------------- /sastgrep.py: -------------------------------------------------------------------------------- 1 | 2 | import shlex,subprocess,html 3 | import re 4 | def initate_grep_command(Args): 5 | try: 6 | Output=subprocess.check_output(Args) 7 | return Output 8 | except: 9 | Output="Grep Command Was Insuccessful" 10 | return Output 11 | 12 | 13 | def sort_data_from_grep_command(CommandOutput): 14 | SastDataDict={} 15 | SastDataDict['data']=[] 16 | CommandOutput=CommandOutput.decode('utf-8') 17 | CommandOutput=CommandOutput.split('\n') 18 | for EachLine in CommandOutput: 19 | if len(EachLine)>2: 20 | 21 | try: 22 | TempList=[] 23 | SplitInfo=re.split("(\d{1,}:)",EachLine) 24 | 25 | TempFileName=SplitInfo[0].replace(':','') 26 | TempLineNumber=SplitInfo[1].replace(':','') 27 | TempCode=html.escape(SplitInfo[2]) 28 | TempList.append(TempFileName) 29 | TempList.append(TempLineNumber) 30 | TempList.append(TempCode) 31 | 32 | SastDataDict['data'].append(TempList) 33 | except: 34 | pass 35 | print (SastDataDict) 36 | return SastDataDict 37 | 38 | def command_rec(Command,FolderMarked): 39 | Command='''grep -irnE '''+''' --exclude=*.sample "'''+Command+'" '+FolderMarked 40 | print(Command) 41 | Args=shlex.split(Command) 42 | print(Args) 43 | CommandOutput=initate_grep_command(Args) 44 | print(CommandOutput) 45 | if CommandOutput=="Grep Command Was Insuccessful": 46 | return "Grep Command Was Insuccessful" 47 | Data=sort_data_from_grep_command(CommandOutput) 48 | return Data 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /static/logo_sast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MohitDabas/sastgriper/c553cd7cba15ba3dd04d8e049e0bb23ec78e870c/static/logo_sast.png -------------------------------------------------------------------------------- /templates/demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |For Demo and Working Please Visit This Url.
75 | Writeup 76 |Results
212 | 213 | 214 | 215 | 216 | 217 |Collecting Feedback.Will be updated shortly.
75 | 76 |