{"action":"created","comment":{"url":"https://api.github.com/repos/inliniac/suricata/pulls/comments/43030358","id":43030358,"diff_hunk":"@@ -0,0 +1,733 @@\n+/* Copyright (C) 2015 Open Information Security Foundation\n+ *\n+ * You can copy, redistribute or modify this Program under the terms of\n+ * the GNU General Public License version 2 as published by the Free\n+ * Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * version 2 along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n+ * 02110-1301, USA.\n+ */\n+\n+#include \"suricata-common.h\"\n+#include \"detect.h\"\n+#include \"detect-parse.h\"\n+#include \"detect-base64-decode.h\"\n+#include \"util-base64.h\"\n+#include \"util-print.h\"\n+\n+/* Arbitrary maximum buffer size for decoded base64 data. */\n+#define BASE64_DECODE_MAX 65535\n+\n+static const char decode_pattern[] = \"\\\\s*(bytes\\\\s+(\\\\d+),?)?\"\n+    \"\\\\s*(offset\\\\s+(\\\\d+),?)?\"\n+    \"\\\\s*(\\\\w+)?\";\n+static pcre *decode_pcre = NULL;\n+static pcre_extra *decode_pcre_study = NULL;\n+\n+static int DetectBase64DecodeSetup(DetectEngineCtx *, Signature *, char *);\n+static void DetectBase64DecodeFree(void *);\n+static void DetectBase64DecodeRegisterTests(void);\n+\n+void DetectBase64DecodeRegister(void)\n+{\n+    const char *pcre_errptr;\n+    int pcre_erroffset;\n+\n+    sigmatch_table[DETECT_BASE64_DECODE].name = \"base64_decode\";\n+    sigmatch_table[DETECT_BASE64_DECODE].desc =\n+        \"Decodes base64 encoded data.\";\n+    sigmatch_table[DETECT_BASE64_DECODE].url =\n+        \"https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Payload_keywords#base64_decode\";\n+    sigmatch_table[DETECT_BASE64_DECODE].Setup = DetectBase64DecodeSetup;\n+    sigmatch_table[DETECT_BASE64_DECODE].Free = DetectBase64DecodeFree;\n+    sigmatch_table[DETECT_BASE64_DECODE].RegisterTests =\n+        DetectBase64DecodeRegisterTests;\n+\n+    sigmatch_table[DETECT_BASE64_DECODE].flags |= SIGMATCH_PAYLOAD;\n+    sigmatch_table[DETECT_BASE64_DECODE].flags |= SIGMATCH_OPTIONAL_OPT;\n+\n+    decode_pcre = pcre_compile(decode_pattern, 0, &pcre_errptr, &pcre_erroffset,\n+        NULL);\n+    if (decode_pcre == NULL) {\n+        SCLogError(SC_ERR_PCRE_COMPILE, \"Failed to compile pattern \\\"%s\\\" at\"\n+            \" offset %d: %s\", decode_pattern, pcre_erroffset, pcre_errptr);\n+        exit(EXIT_FAILURE);\n+    }\n+\n+    decode_pcre_study = pcre_study(decode_pcre, 0, &pcre_errptr);\n+    if (pcre_errptr != NULL) {\n+        SCLogError(SC_ERR_PCRE_STUDY, \"Failed to study pattern \\\"%s\\\": %s\",\n+            decode_pattern, pcre_errptr);\n+        exit(EXIT_FAILURE);\n+    }\n+}\n+\n+int DetectBase64DecodeDoMatch(DetectEngineThreadCtx *det_ctx, Signature *s,\n+    const SigMatch *sm, uint8_t *payload, uint32_t payload_len)\n+{\n+    DetectBase64Decode *data = (DetectBase64Decode *)sm->ctx;\n+    int decode_len;\n+\n+#if 0\n+    printf(\"Input data:\\n\");\n+    PrintRawDataFp(stdout, payload, payload_len);\n+#endif\n+\n+    if (data->relative) {\n+        payload += det_ctx->buffer_offset;\n+        payload_len -= det_ctx->buffer_offset;\n+    }\n+\n+    if (data->offset) {\n+        if (data->offset >= payload_len) {\n+            return 0;\n+        }\n+        payload = payload + data->offset;\n+        payload_len -= data->offset;\n+    }\n+\n+    decode_len = MIN(payload_len, data->bytes);\n+\n+#if 0\n+    printf(\"Decoding:\\n\");\n+    PrintRawDataFp(stdout, payload, decode_len);\n+#endif\n+\n+    det_ctx->base64_decoded_len = DecodeBase64(det_ctx->base64_decoded,\n+        payload, decode_len, 0);\n+    SCLogDebug(\"Decoded %d bytes from base64 data.\",\n+        det_ctx->base64_decoded_len);\n+#if 0\n+    if (det_ctx->base64_decoded_len) {\n+        printf(\"Decoded data:\\n\");\n+        PrintRawDataFp(stdout, det_ctx->base64_decoded,\n+            det_ctx->base64_decoded_len);\n+    }\n+#endif\n+\n+    return det_ctx->base64_decoded_len > 0;\n+}\n+\n+static int ParseUint32(const char *str, uint32_t *value)","path":"src/detect-base64-decode.c","position":118,"original_position":118,"commit_id":"42c32a6846cc0bb65069cc618fe4cd35e3cc8195","original_commit_id":"42c32a6846cc0bb65069cc618fe4cd35e3cc8195","user":{"login":"inliniac","id":719366,"avatar_url":"https://avatars.githubusercontent.com/u/719366?v=3","gravatar_id":"","url":"https://api.github.com/users/inliniac","html_url":"https://github.com/inliniac","followers_url":"https://api.github.com/users/inliniac/followers","following_url":"https://api.github.com/users/inliniac/following{/other_user}","gists_url":"https://api.github.com/users/inliniac/gists{/gist_id}","starred_url":"https://api.github.com/users/inliniac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inliniac/subscriptions","organizations_url":"https://api.github.com/users/inliniac/orgs","repos_url":"https://api.github.com/users/inliniac/repos","events_url":"https://api.github.com/users/inliniac/events{/privacy}","received_events_url":"https://api.github.com/users/inliniac/received_events","type":"User","site_admin":false},"body":"We can use ByteExtractUint32 instead?","created_at":"2015-10-26T18:09:09Z","updated_at":"2015-10-26T18:09:09Z","html_url":"https://github.com/inliniac/suricata/pull/1721#discussion_r43030358","pull_request_url":"https://api.github.com/repos/inliniac/suricata/pulls/1721","_links":{"self":{"href":"https://api.github.com/repos/inliniac/suricata/pulls/comments/43030358"},"html":{"href":"https://github.com/inliniac/suricata/pull/1721#discussion_r43030358"},"pull_request":{"href":"https://api.github.com/repos/inliniac/suricata/pulls/1721"}}},"pull_request":{"url":"https://api.github.com/repos/inliniac/suricata/pulls/1721","id":48759263,"html_url":"https://github.com/inliniac/suricata/pull/1721","diff_url":"https://github.com/inliniac/suricata/pull/1721.diff","patch_url":"https://github.com/inliniac/suricata/pull/1721.patch","issue_url":"https://api.github.com/repos/inliniac/suricata/issues/1721","number":1721,"state":"open","locked":false,"title":"Issue 1282: base64_decode, base64_data - v7","user":{"login":"jasonish","id":644115,"avatar_url":"https://avatars.githubusercontent.com/u/644115?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonish","html_url":"https://github.com/jasonish","followers_url":"https://api.github.com/users/jasonish/followers","following_url":"https://api.github.com/users/jasonish/following{/other_user}","gists_url":"https://api.github.com/users/jasonish/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonish/subscriptions","organizations_url":"https://api.github.com/users/jasonish/orgs","repos_url":"https://api.github.com/users/jasonish/repos","events_url":"https://api.github.com/users/jasonish/events{/privacy}","received_events_url":"https://api.github.com/users/jasonish/received_events","type":"User","site_admin":false},"body":"Fixes issues in last PR: https://github.com/inliniac/suricata/pull/1690\r\n\r\nFor util-base64, intoduce \"strict\" mode so other uses keep the same behaviour.\r\n\r\nRedmine ticket: https://redmine.openinfosecfoundation.org/issues/1282\r\n\r\nBuildbot output:\r\n- PR jasonish-pcap: https://buildbot.openinfosecfoundation.org/builders/jasonish-pcap/builds/154\r\n- PR jasonish: https://buildbot.openinfosecfoundation.org/builders/jasonish/builds/155\r\n","created_at":"2015-10-26T16:03:56Z","updated_at":"2015-10-26T18:09:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4a13eac0573fd1d15554d11c5a51dd788ecf2784","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/inliniac/suricata/pulls/1721/commits","review_comments_url":"https://api.github.com/repos/inliniac/suricata/pulls/1721/comments","review_comment_url":"https://api.github.com/repos/inliniac/suricata/pulls/comments{/number}","comments_url":"https://api.github.com/repos/inliniac/suricata/issues/1721/comments","statuses_url":"https://api.github.com/repos/inliniac/suricata/statuses/42c32a6846cc0bb65069cc618fe4cd35e3cc8195","head":{"label":"jasonish:issue-1282-base64_decode-7","ref":"issue-1282-base64_decode-7","sha":"42c32a6846cc0bb65069cc618fe4cd35e3cc8195","user":{"login":"jasonish","id":644115,"avatar_url":"https://avatars.githubusercontent.com/u/644115?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonish","html_url":"https://github.com/jasonish","followers_url":"https://api.github.com/users/jasonish/followers","following_url":"https://api.github.com/users/jasonish/following{/other_user}","gists_url":"https://api.github.com/users/jasonish/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonish/subscriptions","organizations_url":"https://api.github.com/users/jasonish/orgs","repos_url":"https://api.github.com/users/jasonish/repos","events_url":"https://api.github.com/users/jasonish/events{/privacy}","received_events_url":"https://api.github.com/users/jasonish/received_events","type":"User","site_admin":false},"repo":{"id":5414542,"name":"suricata","full_name":"jasonish/suricata","owner":{"login":"jasonish","id":644115,"avatar_url":"https://avatars.githubusercontent.com/u/644115?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonish","html_url":"https://github.com/jasonish","followers_url":"https://api.github.com/users/jasonish/followers","following_url":"https://api.github.com/users/jasonish/following{/other_user}","gists_url":"https://api.github.com/users/jasonish/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonish/subscriptions","organizations_url":"https://api.github.com/users/jasonish/orgs","repos_url":"https://api.github.com/users/jasonish/repos","events_url":"https://api.github.com/users/jasonish/events{/privacy}","received_events_url":"https://api.github.com/users/jasonish/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jasonish/suricata","description":"Mirror of the official OISF Suricata git repository","fork":true,"url":"https://api.github.com/repos/jasonish/suricata","forks_url":"https://api.github.com/repos/jasonish/suricata/forks","keys_url":"https://api.github.com/repos/jasonish/suricata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jasonish/suricata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jasonish/suricata/teams","hooks_url":"https://api.github.com/repos/jasonish/suricata/hooks","issue_events_url":"https://api.github.com/repos/jasonish/suricata/issues/events{/number}","events_url":"https://api.github.com/repos/jasonish/suricata/events","assignees_url":"https://api.github.com/repos/jasonish/suricata/assignees{/user}","branches_url":"https://api.github.com/repos/jasonish/suricata/branches{/branch}","tags_url":"https://api.github.com/repos/jasonish/suricata/tags","blobs_url":"https://api.github.com/repos/jasonish/suricata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jasonish/suricata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jasonish/suricata/git/refs{/sha}","trees_url":"https://api.github.com/repos/jasonish/suricata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jasonish/suricata/statuses/{sha}","languages_url":"https://api.github.com/repos/jasonish/suricata/languages","stargazers_url":"https://api.github.com/repos/jasonish/suricata/stargazers","contributors_url":"https://api.github.com/repos/jasonish/suricata/contributors","subscribers_url":"https://api.github.com/repos/jasonish/suricata/subscribers","subscription_url":"https://api.github.com/repos/jasonish/suricata/subscription","commits_url":"https://api.github.com/repos/jasonish/suricata/commits{/sha}","git_commits_url":"https://api.github.com/repos/jasonish/suricata/git/commits{/sha}","comments_url":"https://api.github.com/repos/jasonish/suricata/comments{/number}","issue_comment_url":"https://api.github.com/repos/jasonish/suricata/issues/comments{/number}","contents_url":"https://api.github.com/repos/jasonish/suricata/contents/{+path}","compare_url":"https://api.github.com/repos/jasonish/suricata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jasonish/suricata/merges","archive_url":"https://api.github.com/repos/jasonish/suricata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jasonish/suricata/downloads","issues_url":"https://api.github.com/repos/jasonish/suricata/issues{/number}","pulls_url":"https://api.github.com/repos/jasonish/suricata/pulls{/number}","milestones_url":"https://api.github.com/repos/jasonish/suricata/milestones{/number}","notifications_url":"https://api.github.com/repos/jasonish/suricata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jasonish/suricata/labels{/name}","releases_url":"https://api.github.com/repos/jasonish/suricata/releases{/id}","created_at":"2012-08-14T15:13:38Z","updated_at":"2015-05-08T15:33:21Z","pushed_at":"2015-10-26T15:34:58Z","git_url":"git://github.com/jasonish/suricata.git","ssh_url":"git@github.com:jasonish/suricata.git","clone_url":"https://github.com/jasonish/suricata.git","svn_url":"https://github.com/jasonish/suricata","homepage":"http://www.openinfosecfoundation.org","size":42479,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"inliniac:master","ref":"master","sha":"86711a1332f7082a688ff68ad38f2641bd20ee26","user":{"login":"inliniac","id":719366,"avatar_url":"https://avatars.githubusercontent.com/u/719366?v=3","gravatar_id":"","url":"https://api.github.com/users/inliniac","html_url":"https://github.com/inliniac","followers_url":"https://api.github.com/users/inliniac/followers","following_url":"https://api.github.com/users/inliniac/following{/other_user}","gists_url":"https://api.github.com/users/inliniac/gists{/gist_id}","starred_url":"https://api.github.com/users/inliniac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inliniac/subscriptions","organizations_url":"https://api.github.com/users/inliniac/orgs","repos_url":"https://api.github.com/users/inliniac/repos","events_url":"https://api.github.com/users/inliniac/events{/privacy}","received_events_url":"https://api.github.com/users/inliniac/received_events","type":"User","site_admin":false},"repo":{"id":5410234,"name":"suricata","full_name":"inliniac/suricata","owner":{"login":"inliniac","id":719366,"avatar_url":"https://avatars.githubusercontent.com/u/719366?v=3","gravatar_id":"","url":"https://api.github.com/users/inliniac","html_url":"https://github.com/inliniac","followers_url":"https://api.github.com/users/inliniac/followers","following_url":"https://api.github.com/users/inliniac/following{/other_user}","gists_url":"https://api.github.com/users/inliniac/gists{/gist_id}","starred_url":"https://api.github.com/users/inliniac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inliniac/subscriptions","organizations_url":"https://api.github.com/users/inliniac/orgs","repos_url":"https://api.github.com/users/inliniac/repos","events_url":"https://api.github.com/users/inliniac/events{/privacy}","received_events_url":"https://api.github.com/users/inliniac/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/inliniac/suricata","description":"Mirror of the official OISF Suricata git repository","fork":false,"url":"https://api.github.com/repos/inliniac/suricata","forks_url":"https://api.github.com/repos/inliniac/suricata/forks","keys_url":"https://api.github.com/repos/inliniac/suricata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inliniac/suricata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inliniac/suricata/teams","hooks_url":"https://api.github.com/repos/inliniac/suricata/hooks","issue_events_url":"https://api.github.com/repos/inliniac/suricata/issues/events{/number}","events_url":"https://api.github.com/repos/inliniac/suricata/events","assignees_url":"https://api.github.com/repos/inliniac/suricata/assignees{/user}","branches_url":"https://api.github.com/repos/inliniac/suricata/branches{/branch}","tags_url":"https://api.github.com/repos/inliniac/suricata/tags","blobs_url":"https://api.github.com/repos/inliniac/suricata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inliniac/suricata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inliniac/suricata/git/refs{/sha}","trees_url":"https://api.github.com/repos/inliniac/suricata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inliniac/suricata/statuses/{sha}","languages_url":"https://api.github.com/repos/inliniac/suricata/languages","stargazers_url":"https://api.github.com/repos/inliniac/suricata/stargazers","contributors_url":"https://api.github.com/repos/inliniac/suricata/contributors","subscribers_url":"https://api.github.com/repos/inliniac/suricata/subscribers","subscription_url":"https://api.github.com/repos/inliniac/suricata/subscription","commits_url":"https://api.github.com/repos/inliniac/suricata/commits{/sha}","git_commits_url":"https://api.github.com/repos/inliniac/suricata/git/commits{/sha}","comments_url":"https://api.github.com/repos/inliniac/suricata/comments{/number}","issue_comment_url":"https://api.github.com/repos/inliniac/suricata/issues/comments{/number}","contents_url":"https://api.github.com/repos/inliniac/suricata/contents/{+path}","compare_url":"https://api.github.com/repos/inliniac/suricata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inliniac/suricata/merges","archive_url":"https://api.github.com/repos/inliniac/suricata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inliniac/suricata/downloads","issues_url":"https://api.github.com/repos/inliniac/suricata/issues{/number}","pulls_url":"https://api.github.com/repos/inliniac/suricata/pulls{/number}","milestones_url":"https://api.github.com/repos/inliniac/suricata/milestones{/number}","notifications_url":"https://api.github.com/repos/inliniac/suricata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inliniac/suricata/labels{/name}","releases_url":"https://api.github.com/repos/inliniac/suricata/releases{/id}","created_at":"2012-08-14T08:30:06Z","updated_at":"2015-10-20T09:31:40Z","pushed_at":"2015-10-26T16:03:57Z","git_url":"git://github.com/inliniac/suricata.git","ssh_url":"git@github.com:inliniac/suricata.git","clone_url":"https://github.com/inliniac/suricata.git","svn_url":"https://github.com/inliniac/suricata","homepage":"http://suricata-ids.org/","size":63845,"stargazers_count":207,"watchers_count":207,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":191,"mirror_url":null,"open_issues_count":31,"forks":191,"open_issues":31,"watchers":207,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/inliniac/suricata/pulls/1721"},"html":{"href":"https://github.com/inliniac/suricata/pull/1721"},"issue":{"href":"https://api.github.com/repos/inliniac/suricata/issues/1721"},"comments":{"href":"https://api.github.com/repos/inliniac/suricata/issues/1721/comments"},"review_comments":{"href":"https://api.github.com/repos/inliniac/suricata/pulls/1721/comments"},"review_comment":{"href":"https://api.github.com/repos/inliniac/suricata/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/inliniac/suricata/pulls/1721/commits"},"statuses":{"href":"https://api.github.com/repos/inliniac/suricata/statuses/42c32a6846cc0bb65069cc618fe4cd35e3cc8195"}}}}