We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
MalShare uploader not working
**Describe the bug**
In my config I have
```
[output_malshare]
enabled = true
```

and in my logs I have
```
[stdout#info] Sending file to MalShare
[stdout#info] Submited to MalShare
```

but when I check on MalShare I can't find any the binaries that have been caught in my honeypot.

**To Reproduce**
Steps to reproduce the behavior:
1. Enable MalShare submission in your config
2. Wait for a bot to drop a binary in your honeypot
3. Try to find the binary on malshare (search by md5)
4. Observe that the binary is not there

**Expected behavior**
The binary should be uploaded successfully to MalShare

**Server (please complete the following information):**
 - OS: [e.g. RedHat Linux 7.1, output of uname -a] Ubuntu 20.04, Linux 5.4.0
 - Python: 3.8.5

**Additional context**
Based on [MalShare's API docs](https://malshare.com/doc.php) it seems that uploading files now requires an API key and a slightly different POST path than the one [defined in cowrie](https://github.com/cowrie/cowrie/blob/b848ec261554ee9128640601eb9a6734b2bffefe/src/cowrie/output/malshare.py#L90). Probably adding an API key option to the config and updating the uploader with the new path and to use the API key will solve this.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cowrie/output/malshare.py`
Content:
```
1 # Copyright (c) 2015 Michel Oosterhof <michel@oosterhof.net>
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 # 3. The names of the author(s) may not be used to endorse or promote
14 #    products derived from this software without specific prior written
15 #    permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS`` AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 # SUCH DAMAGE.
28 
29 """
30 Send files to https://malshare.com/
31 More info https://malshare.com/doc.php
32 """
33 
34 from __future__ import absolute_import, division
35 
36 import os
37 
38 try:
39     from urllib.parse import urlparse
40 except ImportError:
41     from urlparse import urlparse
42 import requests
43 
44 import cowrie.core.output
45 
46 
47 class Output(cowrie.core.output.Output):
48     """
49     malshare output
50 
51     TODO: use `treq`
52     """
53     def start(self):
54         """
55         Start output plugin
56         """
57         pass
58 
59     def stop(self):
60         """
61         Stop output plugin
62         """
63         pass
64 
65     def write(self, entry):
66         if entry["eventid"] == "cowrie.session.file_download":
67             print("Sending file to MalShare")
68             p = urlparse(entry["url"]).path
69             if p == "":
70                 fileName = entry["shasum"]
71             else:
72                 b = os.path.basename(p)
73                 if b == "":
74                     fileName = entry["shasum"]
75                 else:
76                     fileName = b
77 
78             self.postfile(entry["outfile"], fileName)
79 
80         elif entry["eventid"] == "cowrie.session.file_upload":
81             print("Sending file to MalShare")
82             self.postfile(entry["outfile"], entry["filename"])
83 
84     def postfile(self, artifact, fileName):
85         """
86         Send a file to MalShare
87         """
88         try:
89             res = requests.post(
90                 "https://malshare.com/api.php?mode=cli",
91                 files={fileName: open(artifact, "rb")}
92             )
93             if res and res.ok:
94                 print("Submited to MalShare")
95             else:
96                 print("MalShare Request failed: {}".format(res.status_code))
97         except Exception as e:
98             print("MalShare Request failed: {}".format(e))
99
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/cowrie/output/malshare.py b/src/cowrie/output/malshare.py
--- a/src/cowrie/output/malshare.py
+++ b/src/cowrie/output/malshare.py
@@ -41,7 +41,10 @@
     from urlparse import urlparse
 import requests
 
+from twisted.python import log
+
 import cowrie.core.output
+from cowrie.core.config import CowrieConfig
 
 
 class Output(cowrie.core.output.Output):
@@ -54,7 +57,7 @@
         """
         Start output plugin
         """
-        pass
+        self.apiKey = CowrieConfig().get('output_malshare', 'api_key')
 
     def stop(self):
         """
@@ -64,7 +67,6 @@
 
     def write(self, entry):
         if entry["eventid"] == "cowrie.session.file_download":
-            print("Sending file to MalShare")
             p = urlparse(entry["url"]).path
             if p == "":
                 fileName = entry["shasum"]
@@ -78,7 +80,6 @@
             self.postfile(entry["outfile"], fileName)
 
         elif entry["eventid"] == "cowrie.session.file_upload":
-            print("Sending file to MalShare")
             self.postfile(entry["outfile"], entry["filename"])
 
     def postfile(self, artifact, fileName):
@@ -87,12 +88,12 @@
         """
         try:
             res = requests.post(
-                "https://malshare.com/api.php?mode=cli",
-                files={fileName: open(artifact, "rb")}
+                "https://malshare.com/api.php?api_key="+self.apiKey+"&action=upload",
+                files={"upload": open(artifact, "rb")}
             )
             if res and res.ok:
-                print("Submited to MalShare")
+                log.msg("Submitted to MalShare")
             else:
-                print("MalShare Request failed: {}".format(res.status_code))
+                log.msg("MalShare Request failed: {}".format(res.status_code))
         except Exception as e:
-            print("MalShare Request failed: {}".format(e))
+            log.msg("MalShare Request failed: {}".format(e))

{"golden_diff": "diff --git a/src/cowrie/output/malshare.py b/src/cowrie/output/malshare.py\n--- a/src/cowrie/output/malshare.py\n+++ b/src/cowrie/output/malshare.py\n@@ -41,7 +41,10 @@\n     from urlparse import urlparse\n import requests\n \n+from twisted.python import log\n+\n import cowrie.core.output\n+from cowrie.core.config import CowrieConfig\n \n \n class Output(cowrie.core.output.Output):\n@@ -54,7 +57,7 @@\n         \"\"\"\n         Start output plugin\n         \"\"\"\n-        pass\n+        self.apiKey = CowrieConfig().get('output_malshare', 'api_key')\n \n     def stop(self):\n         \"\"\"\n@@ -64,7 +67,6 @@\n \n     def write(self, entry):\n         if entry[\"eventid\"] == \"cowrie.session.file_download\":\n-            print(\"Sending file to MalShare\")\n             p = urlparse(entry[\"url\"]).path\n             if p == \"\":\n                 fileName = entry[\"shasum\"]\n@@ -78,7 +80,6 @@\n             self.postfile(entry[\"outfile\"], fileName)\n \n         elif entry[\"eventid\"] == \"cowrie.session.file_upload\":\n-            print(\"Sending file to MalShare\")\n             self.postfile(entry[\"outfile\"], entry[\"filename\"])\n \n     def postfile(self, artifact, fileName):\n@@ -87,12 +88,12 @@\n         \"\"\"\n         try:\n             res = requests.post(\n-                \"https://malshare.com/api.php?mode=cli\",\n-                files={fileName: open(artifact, \"rb\")}\n+                \"https://malshare.com/api.php?api_key=\"+self.apiKey+\"&action=upload\",\n+                files={\"upload\": open(artifact, \"rb\")}\n             )\n             if res and res.ok:\n-                print(\"Submited to MalShare\")\n+                log.msg(\"Submitted to MalShare\")\n             else:\n-                print(\"MalShare Request failed: {}\".format(res.status_code))\n+                log.msg(\"MalShare Request failed: {}\".format(res.status_code))\n         except Exception as e:\n-            print(\"MalShare Request failed: {}\".format(e))\n+            log.msg(\"MalShare Request failed: {}\".format(e))\n", "issue": "MalShare uploader not working\n**Describe the bug**\r\nIn my config I have\r\n```\r\n[output_malshare]\r\nenabled = true\r\n```\r\n\r\nand in my logs I have\r\n```\r\n[stdout#info] Sending file to MalShare\r\n[stdout#info] Submited to MalShare\r\n```\r\n\r\nbut when I check on MalShare I can't find any the binaries that have been caught in my honeypot.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Enable MalShare submission in your config\r\n2. Wait for a bot to drop a binary in your honeypot\r\n3. Try to find the binary on malshare (search by md5)\r\n4. Observe that the binary is not there\r\n\r\n**Expected behavior**\r\nThe binary should be uploaded successfully to MalShare\r\n\r\n**Server (please complete the following information):**\r\n - OS: [e.g. RedHat Linux 7.1, output of uname -a] Ubuntu 20.04, Linux 5.4.0\r\n - Python: 3.8.5\r\n\r\n**Additional context**\r\nBased on [MalShare's API docs](https://malshare.com/doc.php) it seems that uploading files now requires an API key and a slightly different POST path than the one [defined in cowrie](https://github.com/cowrie/cowrie/blob/b848ec261554ee9128640601eb9a6734b2bffefe/src/cowrie/output/malshare.py#L90). Probably adding an API key option to the config and updating the uploader with the new path and to use the API key will solve this.\r\n\n", "before_files": [{"content": "# Copyright (c) 2015 Michel Oosterhof <michel@oosterhof.net>\n# All rights reserved.\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions\n# are met:\n#\n# 1. Redistributions of source code must retain the above copyright\n#    notice, this list of conditions and the following disclaimer.\n# 2. Redistributions in binary form must reproduce the above copyright\n#    notice, this list of conditions and the following disclaimer in the\n#    documentation and/or other materials provided with the distribution.\n# 3. The names of the author(s) may not be used to endorse or promote\n#    products derived from this software without specific prior written\n#    permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS`` AND ANY EXPRESS OR\n# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,\n# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\n# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n# SUCH DAMAGE.\n\n\"\"\"\nSend files to https://malshare.com/\nMore info https://malshare.com/doc.php\n\"\"\"\n\nfrom __future__ import absolute_import, division\n\nimport os\n\ntry:\n    from urllib.parse import urlparse\nexcept ImportError:\n    from urlparse import urlparse\nimport requests\n\nimport cowrie.core.output\n\n\nclass Output(cowrie.core.output.Output):\n    \"\"\"\n    malshare output\n\n    TODO: use `treq`\n    \"\"\"\n    def start(self):\n        \"\"\"\n        Start output plugin\n        \"\"\"\n        pass\n\n    def stop(self):\n        \"\"\"\n        Stop output plugin\n        \"\"\"\n        pass\n\n    def write(self, entry):\n        if entry[\"eventid\"] == \"cowrie.session.file_download\":\n            print(\"Sending file to MalShare\")\n            p = urlparse(entry[\"url\"]).path\n            if p == \"\":\n                fileName = entry[\"shasum\"]\n            else:\n                b = os.path.basename(p)\n                if b == \"\":\n                    fileName = entry[\"shasum\"]\n                else:\n                    fileName = b\n\n            self.postfile(entry[\"outfile\"], fileName)\n\n        elif entry[\"eventid\"] == \"cowrie.session.file_upload\":\n            print(\"Sending file to MalShare\")\n            self.postfile(entry[\"outfile\"], entry[\"filename\"])\n\n    def postfile(self, artifact, fileName):\n        \"\"\"\n        Send a file to MalShare\n        \"\"\"\n        try:\n            res = requests.post(\n                \"https://malshare.com/api.php?mode=cli\",\n                files={fileName: open(artifact, \"rb\")}\n            )\n            if res and res.ok:\n                print(\"Submited to MalShare\")\n            else:\n                print(\"MalShare Request failed: {}\".format(res.status_code))\n        except Exception as e:\n            print(\"MalShare Request failed: {}\".format(e))\n", "path": "src/cowrie/output/malshare.py"}], "after_files": [{"content": "# Copyright (c) 2015 Michel Oosterhof <michel@oosterhof.net>\n# All rights reserved.\n#\n# Redistribution and use in source and binary forms, with or without\n# modification, are permitted provided that the following conditions\n# are met:\n#\n# 1. Redistributions of source code must retain the above copyright\n#    notice, this list of conditions and the following disclaimer.\n# 2. Redistributions in binary form must reproduce the above copyright\n#    notice, this list of conditions and the following disclaimer in the\n#    documentation and/or other materials provided with the distribution.\n# 3. The names of the author(s) may not be used to endorse or promote\n#    products derived from this software without specific prior written\n#    permission.\n#\n# THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS`` AND ANY EXPRESS OR\n# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,\n# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\n# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\n# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n# SUCH DAMAGE.\n\n\"\"\"\nSend files to https://malshare.com/\nMore info https://malshare.com/doc.php\n\"\"\"\n\nfrom __future__ import absolute_import, division\n\nimport os\n\ntry:\n    from urllib.parse import urlparse\nexcept ImportError:\n    from urlparse import urlparse\nimport requests\n\nfrom twisted.python import log\n\nimport cowrie.core.output\nfrom cowrie.core.config import CowrieConfig\n\n\nclass Output(cowrie.core.output.Output):\n    \"\"\"\n    malshare output\n\n    TODO: use `treq`\n    \"\"\"\n    def start(self):\n        \"\"\"\n        Start output plugin\n        \"\"\"\n        self.apiKey = CowrieConfig().get('output_malshare', 'api_key')\n\n    def stop(self):\n        \"\"\"\n        Stop output plugin\n        \"\"\"\n        pass\n\n    def write(self, entry):\n        if entry[\"eventid\"] == \"cowrie.session.file_download\":\n            p = urlparse(entry[\"url\"]).path\n            if p == \"\":\n                fileName = entry[\"shasum\"]\n            else:\n                b = os.path.basename(p)\n                if b == \"\":\n                    fileName = entry[\"shasum\"]\n                else:\n                    fileName = b\n\n            self.postfile(entry[\"outfile\"], fileName)\n\n        elif entry[\"eventid\"] == \"cowrie.session.file_upload\":\n            self.postfile(entry[\"outfile\"], entry[\"filename\"])\n\n    def postfile(self, artifact, fileName):\n        \"\"\"\n        Send a file to MalShare\n        \"\"\"\n        try:\n            res = requests.post(\n                \"https://malshare.com/api.php?api_key=\"+self.apiKey+\"&action=upload\",\n                files={\"upload\": open(artifact, \"rb\")}\n            )\n            if res and res.ok:\n                log.msg(\"Submitted to MalShare\")\n            else:\n                log.msg(\"MalShare Request failed: {}\".format(res.status_code))\n        except Exception as e:\n            log.msg(\"MalShare Request failed: {}\".format(e))\n", "path": "src/cowrie/output/malshare.py"}]}