
ओपन सोर्स टूल्स + आपके कोड के थोड़े से हिस्से का उपयोग करके उपयोगी, हल्के स्टैटिक एनालिसिस बनाएं
इस रेपो में ShellCon 2019 वार्ता, "रोलिंग योर ओन: कस्टम, हल्के स्थैतिक विश्लेषण उपकरण कैसे लिखें" (स्लाइड्स) के लिए PoC कोड मौजूद है।
संक्षेप में, यह रेपो कुछ ठोस उदाहरणों के माध्यम से दिखाता है कि कैसे आप ओपन सोर्स उपकरणों और थोड़ी मात्रा में कस्टम कोड का उपयोग करके कुछ दिलचस्प स्थैतिक विश्लेषण बना सकते हैं।
इस रेपो में कोड उदाहरण:
before_actions का उपयोग करता है।उदाहरण कैसे काम करते हैं
उच्च स्तर पर, उदाहरणों का कार्यान्वयन इस प्रकार काम करता है:
इस प्रोजेक्ट को Docker का उपयोग करके चलाने के लिए बनाया गया है।
ऐसा करने के लिए, आपको पहले कुछ चीज़ें सेट करनी होंगी।
चूँकि हमारा Dockerfile semantic Docker इमेज पर आधारित है, जो GitHub के पैकेज रजिस्ट्री पर होस्ट है, इसलिए आपको GitHub Package Registry के साथ उपयोग के लिए Docker को कॉन्फ़िगर करना होगा।
$ docker login docker.pkg.github.com -u USERNAME -p TOKENdocker build -t lightweight_static_analysis .bash शेल चलाएँ और फिर हमारी स्क्रिप्ट चलाएँ।# Run this
# (Make sure to run this from a terminal in this repo's project root)
$ docker run -it --rm --entrypoint /bin/bash -v $PWD:/lightweight_static_analysis lightweight_static_analysis
# cd into this project's source code within the
# running container
$ cd /lightweight_static_analysis
# Run main.py with different config options, described further below
Docker कंटेनर में bash शेल प्राप्त करने के बाद (docker run कमांड के लिए ऊपर देखें), आप कई संभावित मोडों में से एक के साथ main.py चला सकते हैं।
/lightweight_static_analysis> $ python3 src/main.py <options>
आप सभी उपलब्ध विकल्पों को बिना किसी विकल्प के src/main.py चलाकर या main.py के parser.add_argument अनुभाग को देखकर जान सकते हैं।
यहाँ कुछ कमांड दिए गए हैं जो Rails कोडबेस को इंटरैक्टिव रूप से एक्सप्लोर करने में आपकी मदद कर सकते हैं।
सबसे पहले, आप एक या अधिक Rails रेपो को क्लोन करके examples/ में रखना चाहेंगे। यदि आपको कुछ उदाहरण रेपो चाहिए, तो आप rubygems.org का स्रोत कोड, या Open Source Rails पर सूचीबद्ध किसी एक रेपो का उपयोग कर सकते हैं।
# Print out the class, super class, defined methods, and before actions
# for all controllers
$ python3 src/main.py --rails-summarize-controllers examples/<repo_name>
# Print out every controller name, grouped by super class
#
# This can find examples where security protections defined in a parent class
# (e.g. ApplicationController or Api::BaseController) aren't applied because
# the vulnerable controller didn't subclass the appropriate class.
$ python3 src/main.py --rails-controllers-by-superclass examples/<repo_name>
# For every before_action used by any controller, list the controllers that
# use that before_action and the routes that it is and isn't applied to
# (e.g. handle the 'except' and 'only" keywords)
#
# This can:
# * Give you quick insight the various before_actions the application defines,
# yielding some intuition as to the code's flow and organization.
# * `verify_with_otp` - Hm, that sounds interesting, I probably want to
# review how that filter is implemented.
# * Show you where a given before_action is and isn't applied across an entire
# code base, potentially leading to bugs where it is inconsistently used
#
# For example
# * Is there a before_action that's used to protect all state0-changing API
# routes except for 1 model? That's strange.
# * Is there an authentication or authorization before_action applied to every
# action in a controller except one? Why?
$ python3 src/main.py --rails-controllers-by-before_action examples/<repo_name>
यदि आप पार्सिंग पूरी होने के बाद ipdb REPL में जाना चाहते हैं ताकि आप पार्स किए गए Ruby कोड की इंटरैक्टिव रूप से जाँच कर सकें, तो आप उपरोक्त कमांड में --repl फ़्लैग भी पास करके ऐसा कर सकते हैं।
ये उदाहरण ast_node.py में परिभाषित विभिन्न AstNode क्लासों पर निर्भर करते हैं, और सभी Rails-विशिष्ट कोड ruby.py में है।
exec()s के माध्यम से कमांड इंजेक्शन ढूँढनाइस कार्यान्वयन को अभी तक साफ और प्रलेखित नहीं किया गया है, लेकिन main.py में batch_parse_json() और visitor.py में visit() तथा इसके द्वारा कॉल किए जाने वाले अन्य तरीकों को देखें।
हमें इस कार्य के बारे में अधिक विस्तार से बात करने में खुशी होगी, बेझिझक एक issue खोलें या Twitter पर संपर्क करें: @clintgibler, @defreez.
यदि आप इस और हमारे अन्य प्रोजेक्ट्स के बारे में अपडेट रहना चाहते हैं, तो हमारा tl;dr sec न्यूज़लेटर देखें, जहाँ हम शीर्ष सुरक्षा वार्ताओं के विस्तृत सारांश और सर्वोत्तम सुरक्षा उपकरणों व संसाधनों के लिंक भेजते हैं।
यह एक कम मात्रा, उच्च गुणवत्ता वाला न्यूज़लेटर है जिसका उद्देश्य आपको सुरक्षा के क्षेत्र में नवीनतम और सर्वोत्तम जानकारी से अद्यतन रखना है, ताकि आप अपना काम अधिक कुशलतापूर्वक और प्रभावी ढंग से कर सकें, और अपने infosec वाटरकूलर पर साझा करने के लिए उपयोगी जानकारी पा सकें।