Coverage for graphqler / fuzzer / engine / detectors / os_command_injection / os_command_injection_detector.py: 65%

23 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-18 23:20 -0400

1from typing import Type 

2 

3import requests 

4 

5from .os_command_injection_materializer import OSCommandInjectionMaterializer 

6from ..detector import Detector 

7 

8 

9class OSCommandInjectionDetector(Detector): 

10 """OSCommandInjectionDetector 

11 Will have two main functions: 

12 first will be the materializer to use 

13 second will be the detection function on both the payload and the response 

14 If the malicious payload is detected in the response, the detector will return the vulnerability 

15 """ 

16 @property 

17 def DETECTION_NAME(self) -> str: 

18 return "OS Command Injection" 

19 

20 @property 

21 def detect_only_once_for_api(self) -> bool: 

22 return False 

23 

24 @property 

25 def detect_only_once_for_node(self) -> bool: 

26 return True 

27 

28 @property 

29 def materializer(self) -> Type[OSCommandInjectionMaterializer]: 

30 return OSCommandInjectionMaterializer 

31 

32 def _is_vulnerable(self, graphql_response: dict, request_response: requests.Response) -> bool: 

33 if graphql_response is None or 'data' not in graphql_response or graphql_response['data'] is None: 

34 return False 

35 return "root:x:0:0:root:" in request_response.text or "root:x:0:0:root:" in str(graphql_response['data']) 

36 

37 def _is_potentially_vulnerable(self, graphql_response: dict, request_response: requests.Response) -> bool: 

38 return self._is_vulnerable(graphql_response, request_response)