{"id":17470912,"url":"https://github.com/matsumotory/http-dos-detector","last_synced_at":"2025-07-11T07:42:13.499Z","repository":{"id":33421895,"uuid":"37067163","full_name":"matsumotory/http-dos-detector","owner":"matsumotory","description":"detect huge number of http access like DoS for Apache and nginx using mruby","archived":false,"fork":false,"pushed_at":"2017-05-16T06:15:17.000Z","size":14,"stargazers_count":91,"open_issues_count":0,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-30T08:51:51.789Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matsumotory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-08T13:02:38.000Z","updated_at":"2025-01-10T18:04:26.000Z","dependencies_parsed_at":"2022-08-07T21:16:03.436Z","dependency_job_id":null,"html_url":"https://github.com/matsumotory/http-dos-detector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/matsumotory/http-dos-detector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fhttp-dos-detector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fhttp-dos-detector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fhttp-dos-detector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fhttp-dos-detector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matsumotory","download_url":"https://codeload.github.com/matsumotory/http-dos-detector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fhttp-dos-detector/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264757302,"owners_count":23659326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-18T16:12:25.923Z","updated_at":"2025-07-11T07:42:13.480Z","avatar_url":"https://github.com/matsumotory.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-dos-detector\n\nDetect Huge Number of HTTP Requests on Apache and Nginx using mruby code.\n\nhttp-dos-detector use same Ruby code between Apache(mod_mruby) and nginx(ngx_mruby).\n\n## Install and Configuration\n- install [mod_mruby](https://github.com/matsumoto-r/mod_mruby) if you use apache\n- install [ngx_mruby](https://github.com/matsumoto-r/ngx_mruby) if you use nginx\n\n### Apache and mod_mruby\n- copy `dos_detector/` and `dos_detector_apache.conf` into `/etc/httpd/conf.d/`\n```apache\nLoadModule mruby_module modules/mod_mruby.so\n\n\u003cIfModule mod_mruby.c\u003e\n  mrubyPostConfigMiddle    /etc/httpd/conf.d/dos_detector/dos_detector_init.rb cache\n  mrubyChildInitMiddle     /etc/httpd/conf.d/dos_detector/dos_detector_worker_init.rb cache\n  mrubyAccessCheckerMiddle /etc/httpd/conf.d/dos_detector/dos_detector.rb cache\n\u003c/IfModule\u003e\n```\n\n### nginx and ngx_mruby\n- copy `dos_detector/` into `/path/to/nginx/conf.d/`\n- write configuration like `dos_detector_nginx.conf`\n```nginx\nhttp {\n  mruby_init /path/to/nginx/conf/doc_detector/dos_detector_init.rb cache;\n  mruby_init_worker /path/to/nginx/conf/doc_detector/dos_detector_worker_init.rb cache;\n  server {\n    location /dos_detector {\n      mruby_access_handler /path/to/nginx/conf/doc_detector/dos_detector.rb cache;\n    }\n  }\n}\n```\n### programmable configuration of DoS\n- `dos_detector.rb`\n```ruby\nServer = get_server_class\nr = Server::Request.new\ncache = Userdata.new.shared_cache\nglobal_mutex = Userdata.new.shared_mutex\nhost = r.hostname\n\nconfig = {\n  :counter_key =\u003e r.hostname,\n  :magic_str =\u003e \"....\",\n\n  :behind_counter =\u003e -500,\n\n  :threshold_counter =\u003e 100,\n  :threshold_time =\u003e 1,\n\n  :expire_time =\u003e 5,\n}\n\nunless r.sub_request?\n  # process-shared lock\n  timeout = global_mutex.try_lock_loop(50000) do\n    dos = DosDetector.new r, cache, config\n    data = dos.analyze\n    Server.errlogger Server::LOG_NOTICE, \"[INFO] dos_detetor: detect dos: #{data}\"\n    begin\n      if dos.detect?\n        Server.errlogger Server::LOG_NOTICE, \"dos_detetor: detect dos: #{data}\"\n        Server.return Server::HTTP_SERVICE_UNAVAILABLE\n      end\n    rescue =\u003e e\n      raise \"DosDetector failed: #{e}\"\n    ensure\n      global_mutex.unlock\n    end\n  end\n  if timeout\n    Server.errlogger Server::LOG_NOTICE, \"dos_detetor: get timeout mutex lock, #{data}\"\n  end\nend\n```\n\n## depend mrbgem\n```ruby\n  conf.gem :github =\u003e 'matsumoto-r/mruby-localmemcache'\n  conf.gem :github =\u003e 'matsumoto-r/mruby-mutex'\n```\n\nhttp-dos-detector has the counter of any key in process-shared memory. When Apache or nginx was restarted, the counter was freed.\n\n## License\nunder the MIT License:\n- see LICENSE file\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsumotory%2Fhttp-dos-detector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatsumotory%2Fhttp-dos-detector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsumotory%2Fhttp-dos-detector/lists"}