{"id":3706,"date":"2024-09-27T14:33:52","date_gmt":"2024-09-27T12:33:52","guid":{"rendered":"https:\/\/hardsoftsecurity.es\/?p=3706"},"modified":"2024-09-27T14:35:03","modified_gmt":"2024-09-27T12:35:03","slug":"mssql-python-shell","status":"publish","type":"post","link":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/","title":{"rendered":"MSSQL Python Shell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This post presents an enhanced Python script for interacting with Microsoft SQL Server using the\u00a0<code>pymssql<\/code>\u00a0library. This improved script is based on the original\u00a0<a href=\"https:\/\/github.com\/Alamot\/code-snippets\/blob\/master\/mssql\/mssql_shell.py\">MSSQL\u00a0Shell\u00a0Script<\/a>\u00a0by Alamot. My modified version introduces the use of the more modern and maintained\u00a0<code>pymssql<\/code>\u00a0library and added functionality for file uploads, ensuring that commands and file transfers are handled smoothly. The code has been tested with Python 3.11.9.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"418\" data-attachment-id=\"3708\" data-permalink=\"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/image-69\/\" data-orig-file=\"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?fit=800%2C418&amp;ssl=1\" data-orig-size=\"800,418\" data-comments-opened=\"1\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?fit=800%2C418&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?resize=800%2C418&#038;ssl=1\" alt=\"MSSQL Python Shell\" class=\"wp-image-3708\" srcset=\"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?w=800&amp;ssl=1 800w, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?resize=300%2C157&amp;ssl=1 300w, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?resize=768%2C401&amp;ssl=1 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">Key Differences from the Original Script<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Use of\u00a0<\/strong><code>pymssql<\/code><strong>:<\/strong>\u00a0The original script used older libraries to connect to MSSQL, which were not fully compatible with modern Python versions. The updated script uses\u00a0<code>pymssql<\/code>, which works seamlessly with Python 3.11.9 and beyond.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Improved Error Handling:<\/strong>\u00a0The new version includes better error handling, particularly when enabling\u00a0<code>xp_cmdshell<\/code>\u00a0and when there are database errors during command execution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The function\u00a0<\/strong><code>base64.encodestring()<\/code>:\u00a0was replaced with\u00a0<code>base64.encodebytes()<\/code>\u00a0to ensure compatibility with Python 3.9 and later versions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env python\nfrom __future__ import print_function\n# Author: Alamot\n# Use pymssql >= 1.0.3 (otherwise it doesn't work correctly)\n# To upload a file, type: UPLOAD local_path remote_path\n# e.g. UPLOAD myfile.txt C:\\temp\\myfile.txt\n# If you omit the remote_path it uploads the file on the current working folder.\nimport pymssql\nimport base64\nimport shlex\nimport sys\nimport tqdm\nimport hashlib\nfrom io import open\ntry: input = raw_input\nexcept NameError: pass\n\nMSSQL_SERVER=\"REPLACE\"\nMSSQL_USERNAME = \"REPLACE\"\nMSSQL_PASSWORD = \"REPLACE\"\nBUFFER_SIZE = 5*1024\nTIMEOUT = 30\n\ndef process_result(cursor):\n    username = \"\"\n    computername = \"\"\n    cwd = \"\"\n    rows = cursor.fetchall()\n    for row in rows&#91;:-3]:\n        columns = list(row)\n        if row&#91;-1]:\n            print(row&#91;-1])\n        else:\n            print()\n    if len(rows) >= 3:\n        (username, computername) = rows&#91;-3]&#91;-1].split('|')\n        cwd = rows&#91;-2]&#91;-1]\n    return (username.rstrip(), computername.rstrip(), cwd.rstrip())\n\ndef upload(cursor, stored_cwd, local_path, remote_path):\n    print(\"Uploading \"+local_path+\" to \"+remote_path)\n    cmd = 'type nul > \"' + remote_path + '.b64\"'\n    cursor.execute(\"EXEC xp_cmdshell '\"+cmd+\"'\")\n\n    with open(local_path, 'rb') as f:\n        data = f.read()\n        md5sum = hashlib.md5(data).hexdigest()\n        b64enc_data = b\"\".join(base64.encodebytes(data).split()).decode()\n\n    print(\"Data length (b64-encoded): \"+str(len(b64enc_data)\/1024)+\"KB\")\n    for i in tqdm.tqdm(range(0, len(b64enc_data), BUFFER_SIZE), unit_scale=BUFFER_SIZE\/1024, unit=\"KB\"):\n        cmd = 'echo '+b64enc_data&#91;i:i+BUFFER_SIZE]+' >> \"' + remote_path + '.b64\"'\n        cursor.execute(\"EXEC xp_cmdshell '\"+cmd+\"'\")\n\n    cmd = 'certutil -decode \"' + remote_path + '.b64\" \"' + remote_path + '\"'\n    cursor.execute(\"EXEC xp_cmdshell 'cd \"+stored_cwd+\" &amp; \"+cmd+\" &amp; echo %username%^|%COMPUTERNAME% &amp; cd'\")\n    process_result(cursor)\n    cmd = 'certutil -hashfile \"' + remote_path + '\" MD5'\n    cursor.execute(\"EXEC xp_cmdshell 'cd \"+stored_cwd+\" &amp; \"+cmd+\" &amp; echo %username%^|%COMPUTERNAME% &amp; cd'\")\n    if md5sum in &#91;row&#91;-1].strip() for row in cursor.fetchall() if row&#91;-1]]:\n        print(\"MD5 hashes match: \" + md5sum)\n    else:\n        print(\"ERROR! MD5 hashes do NOT match!\")\n\ndef enable_xp_cmdshell(cursor):\n    try:\n        # Ensure no active transaction before enabling xp_cmdshell\n        cursor.execute(\"IF @@TRANCOUNT > 0 ROLLBACK;\")\n\n        # Enable xp_cmdshell\n        cursor.execute(\"EXEC sp_configure 'show advanced options',1; RECONFIGURE;\")\n        cursor.execute(\"EXEC sp_configure 'xp_cmdshell',1; RECONFIGURE;\")\n        print(\"xp_cmdshell enabled.\")\n    except pymssql.DatabaseError as e:\n        print(f\"Failed to enable xp_cmdshell: {str(e)}\")\n\ndef shell():\n    conn = None\n    stored_cwd = None\n    try:\n        conn = pymssql.connect(server=MSSQL_SERVER, user=MSSQL_USERNAME, password=MSSQL_PASSWORD)\n        cursor = conn.cursor()\n        print(\"Successful login: \"+MSSQL_USERNAME+\"@\"+MSSQL_SERVER)\n\n        # Enable xp_cmdshell\n        enable_xp_cmdshell(cursor)\n\n        # Execute initial commands\n        cmd = 'echo %username%^|%COMPUTERNAME% &amp; cd'\n        cursor.execute(\"EXEC xp_cmdshell '\"+cmd+\"'\")\n        (username, computername, cwd) = process_result(cursor)\n        stored_cwd = cwd\n\n        while True:\n            cmd = input(\"CMD \"+username+\"@\"+computername+\" \"+cwd+\"> \").rstrip(\"\\n\").replace(\"'\", \"''\")\n            if not cmd:\n                cmd = \"call\"  # Dummy cmd command\n            if cmd.lower()&#91;0:4] == \"exit\":\n                conn.close()\n                return\n            elif cmd&#91;0:6] == \"UPLOAD\":\n                upload_cmd = shlex.split(cmd, posix=False)\n                if len(upload_cmd) &lt; 3:\n                    upload(cursor, stored_cwd, upload_cmd&#91;1], stored_cwd+\"\\\\\"+upload_cmd&#91;1])\n                else:\n                    upload(cursor, stored_cwd, upload_cmd&#91;1], upload_cmd&#91;2])\n                cmd = \"echo *** UPLOAD PROCEDURE FINISHED ***\"\n            cursor.execute(\"EXEC xp_cmdshell 'cd \"+stored_cwd+\" &amp; \"+cmd+\" &amp; echo %username%^|%COMPUTERNAME% &amp; cd'\")\n            (username, computername, cwd) = process_result(cursor)\n            stored_cwd = cwd\n\n    except pymssql.DatabaseError as e:\n        print(f\"Database error: {str(e)}\")\n    finally:\n        if conn:\n            conn.close()\n\nshell()\nsys.exit()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I want to extend a special thanks to&nbsp;<strong>Alamot<\/strong>&nbsp;for the original&nbsp;<a href=\"https:\/\/github.com\/Alamot\/code-snippets\/blob\/master\/mssql\/mssql_shell.py\">MSSQL&nbsp;Shell&nbsp;Script<\/a>&nbsp;that served as the foundation for this improved version. The original code provided a solid base to work from and allowed for these enhancements to be implemented seamlessly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To everyone reading this post, I hope this updated script proves helpful in your work with MSSQL. If you have any questions or further suggestions for improvements, feel free to reach out. Wishing you all the best in your coding journey, and may your scripts always run smoothly!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy coding!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post presents an enhanced Python script for interacting with Microsoft SQL Server using the\u00a0pymssql\u00a0library. This improved script is based on the original\u00a0MSSQL\u00a0Shell\u00a0Script\u00a0by Alamot. My modified version introduces the use &#8230;<\/p>\n","protected":false},"author":1,"featured_media":3708,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3,7],"tags":[532,529,531,525,44,534,533,528],"class_list":["post-3706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guias","category-seguridad-informatica","tag-checksum","tag-file-upload","tag-md5","tag-mssql","tag-python","tag-scripting","tag-sql-server","tag-xp_cmdshell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MSSQL Python Shell - Hardsoft Security<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MSSQL Python Shell - Hardsoft Security\" \/>\n<meta property=\"og:description\" content=\"This post presents an enhanced Python script for interacting with Microsoft SQL Server using the\u00a0pymssql\u00a0library. This improved script is based on the original\u00a0MSSQL\u00a0Shell\u00a0Script\u00a0by Alamot. My modified version introduces the use ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/\" \/>\n<meta property=\"og:site_name\" content=\"Hardsoft Security\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/HardSoftDavid\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-27T12:33:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-27T12:35:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"418\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"david\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DavidDeMaya\" \/>\n<meta name=\"twitter:site\" content=\"@DavidDeMaya\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"david\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/\"},\"author\":{\"name\":\"david\",\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/#\\\/schema\\\/person\\\/dfe289b1e4ae2daf72695e85a8b3dd7a\"},\"headline\":\"MSSQL Python Shell\",\"datePublished\":\"2024-09-27T12:33:52+00:00\",\"dateModified\":\"2024-09-27T12:35:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/\"},\"wordCount\":239,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/hardsoftsecurity.es\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/image-1.png?fit=800%2C418&ssl=1\",\"keywords\":[\"checksum\",\"file-upload\",\"md5\",\"mssql\",\"python\",\"scripting\",\"sql-server\",\"xp_cmdshell\"],\"articleSection\":[\"Gu\u00edas\",\"Seguridad inform\u00e1tica\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/\",\"url\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/\",\"name\":\"MSSQL Python Shell - Hardsoft Security\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/hardsoftsecurity.es\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/image-1.png?fit=800%2C418&ssl=1\",\"datePublished\":\"2024-09-27T12:33:52+00:00\",\"dateModified\":\"2024-09-27T12:35:03+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/#\\\/schema\\\/person\\\/dfe289b1e4ae2daf72695e85a8b3dd7a\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/hardsoftsecurity.es\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/image-1.png?fit=800%2C418&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/hardsoftsecurity.es\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/image-1.png?fit=800%2C418&ssl=1\",\"width\":800,\"height\":418},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/index.php\\\/2024\\\/09\\\/27\\\/mssql-python-shell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\\\/\\\/hardsoftsecurity.es\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MSSQL Python Shell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/#website\",\"url\":\"https:\\\/\\\/hardsoftsecurity.es\\\/\",\"name\":\"Hardsoft Security\",\"description\":\"Chasing (In)Security\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/hardsoftsecurity.es\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/hardsoftsecurity.es\\\/#\\\/schema\\\/person\\\/dfe289b1e4ae2daf72695e85a8b3dd7a\",\"name\":\"david\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/868972cb4e72674a12503e080ee081285c7df2fde82787c96a74bca20781cad7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/868972cb4e72674a12503e080ee081285c7df2fde82787c96a74bca20781cad7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/868972cb4e72674a12503e080ee081285c7df2fde82787c96a74bca20781cad7?s=96&d=mm&r=g\",\"caption\":\"david\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MSSQL Python Shell - Hardsoft Security","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/","og_locale":"es_ES","og_type":"article","og_title":"MSSQL Python Shell - Hardsoft Security","og_description":"This post presents an enhanced Python script for interacting with Microsoft SQL Server using the\u00a0pymssql\u00a0library. This improved script is based on the original\u00a0MSSQL\u00a0Shell\u00a0Script\u00a0by Alamot. My modified version introduces the use ...","og_url":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/","og_site_name":"Hardsoft Security","article_publisher":"https:\/\/www.facebook.com\/HardSoftDavid","article_published_time":"2024-09-27T12:33:52+00:00","article_modified_time":"2024-09-27T12:35:03+00:00","og_image":[{"width":800,"height":418,"url":"https:\/\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png","type":"image\/png"}],"author":"david","twitter_card":"summary_large_image","twitter_creator":"@DavidDeMaya","twitter_site":"@DavidDeMaya","twitter_misc":{"Escrito por":"david","Tiempo de lectura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/#article","isPartOf":{"@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/"},"author":{"name":"david","@id":"https:\/\/hardsoftsecurity.es\/#\/schema\/person\/dfe289b1e4ae2daf72695e85a8b3dd7a"},"headline":"MSSQL Python Shell","datePublished":"2024-09-27T12:33:52+00:00","dateModified":"2024-09-27T12:35:03+00:00","mainEntityOfPage":{"@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/"},"wordCount":239,"commentCount":0,"image":{"@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?fit=800%2C418&ssl=1","keywords":["checksum","file-upload","md5","mssql","python","scripting","sql-server","xp_cmdshell"],"articleSection":["Gu\u00edas","Seguridad inform\u00e1tica"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/","url":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/","name":"MSSQL Python Shell - Hardsoft Security","isPartOf":{"@id":"https:\/\/hardsoftsecurity.es\/#website"},"primaryImageOfPage":{"@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/#primaryimage"},"image":{"@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?fit=800%2C418&ssl=1","datePublished":"2024-09-27T12:33:52+00:00","dateModified":"2024-09-27T12:35:03+00:00","author":{"@id":"https:\/\/hardsoftsecurity.es\/#\/schema\/person\/dfe289b1e4ae2daf72695e85a8b3dd7a"},"breadcrumb":{"@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/#primaryimage","url":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?fit=800%2C418&ssl=1","contentUrl":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?fit=800%2C418&ssl=1","width":800,"height":418},{"@type":"BreadcrumbList","@id":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/09\/27\/mssql-python-shell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/hardsoftsecurity.es\/"},{"@type":"ListItem","position":2,"name":"MSSQL Python Shell"}]},{"@type":"WebSite","@id":"https:\/\/hardsoftsecurity.es\/#website","url":"https:\/\/hardsoftsecurity.es\/","name":"Hardsoft Security","description":"Chasing (In)Security","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/hardsoftsecurity.es\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Person","@id":"https:\/\/hardsoftsecurity.es\/#\/schema\/person\/dfe289b1e4ae2daf72695e85a8b3dd7a","name":"david","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/secure.gravatar.com\/avatar\/868972cb4e72674a12503e080ee081285c7df2fde82787c96a74bca20781cad7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/868972cb4e72674a12503e080ee081285c7df2fde82787c96a74bca20781cad7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/868972cb4e72674a12503e080ee081285c7df2fde82787c96a74bca20781cad7?s=96&d=mm&r=g","caption":"david"}}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7xGFx-XM","jetpack-related-posts":[{"id":3894,"url":"https:\/\/hardsoftsecurity.es\/index.php\/2026\/01\/19\/python-cache-poisoning-privesc-linux\/","url_meta":{"origin":3706,"position":0},"title":"Python Cache Poisoning &#8211; PrivEsc &#8211; Linux","author":"david","date":"enero 19, 2026","format":false,"excerpt":"Introduction Python cache poisoning is a lesser-known but powerful technique that can lead to local privilege escalation (priv\u2011esc) in misconfigured environments. It abuses how Python compiles and caches bytecode (.pyc files) to speed up execution. When an attacker can influence which bytecode is loaded\u2014or where it is loaded from\u2014they may\u2026","rel":"","context":"En \u00abGu\u00edas\u00bb","block_context":{"text":"Gu\u00edas","link":"https:\/\/hardsoftsecurity.es\/index.php\/category\/guias\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/01\/hacking.png?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/01\/hacking.png?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/01\/hacking.png?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/01\/hacking.png?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/01\/hacking.png?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3991,"url":"https:\/\/hardsoftsecurity.es\/index.php\/2026\/08\/26\/offensive-ai-vulnerable-mcp-server-lab\/","url_meta":{"origin":3706,"position":1},"title":"Offensive AI &#8211; Vulnerable MCP Server Lab","author":"david","date":"agosto 26, 2026","format":false,"excerpt":"A self-hosted, intentionally vulnerable MCP (Model Context Protocol) server for security research and education. This lab demonstrates how MCP servers can be enumerated, interacted with, and exploited using common vulnerability classes. WARNING:\u00a0This lab is intentionally vulnerable. Run it in an isolated environment only. Do not expose it to the internet.\u2026","rel":"","context":"En \u00abGu\u00edas\u00bb","block_context":{"text":"Gu\u00edas","link":"https:\/\/hardsoftsecurity.es\/index.php\/category\/guias\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/08\/image.png?fit=753%2C271&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/08\/image.png?fit=753%2C271&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/08\/image.png?fit=753%2C271&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2026\/08\/image.png?fit=753%2C271&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":746,"url":"https:\/\/hardsoftsecurity.es\/index.php\/2016\/02\/09\/generador-de-contrasenas-seguras-con-python\/","url_meta":{"origin":3706,"position":2},"title":"Generador De Contrase\u00f1as Seguras Con Python","author":"david","date":"febrero 9, 2016","format":false,"excerpt":"Esta vez os traigo un generador de contrase\u00f1as seguras de 10 d\u00edgitos, es un script basado en python. Aqu\u00ed muestro el funcionamiento del script, al final del post dejare el c\u00f3digo para el que lo quiera modificar. 1.- Paso: Le damos permisos al archivo que contenga nuestro c\u00f3digo. 2.- Paso:\u2026","rel":"","context":"En \u00abGu\u00edas\u00bb","block_context":{"text":"Gu\u00edas","link":"https:\/\/hardsoftsecurity.es\/index.php\/category\/guias\/"},"img":{"alt_text":"python-logo-master-v3-TM","src":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2016\/02\/python-logo-master-v3-tm.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2016\/02\/python-logo-master-v3-tm.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2016\/02\/python-logo-master-v3-tm.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2627,"url":"https:\/\/hardsoftsecurity.es\/index.php\/2021\/11\/24\/script-dnsinfo\/","url_meta":{"origin":3706,"position":3},"title":"Script DNSInfo","author":"david","date":"noviembre 24, 2021","format":false,"excerpt":"Buenas tardes a tod@s, hoy os traigo un post algo diferente a lo habitual en el blog y es que esta vez os traigo un script en Python para extraer informaci\u00f3n p\u00fablica relacionada con el nombre de dominio, que he titulado DNSInfo. \u00bfPor qu\u00e9? Este Script, surge de la necesidad\u2026","rel":"","context":"En \u00abInformaci\u00f3n\u00bb","block_context":{"text":"Informaci\u00f3n","link":"https:\/\/hardsoftsecurity.es\/index.php\/category\/informacion\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2021\/11\/Information-Technology-Wallpaper-HD.jpg?fit=1200%2C300&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2021\/11\/Information-Technology-Wallpaper-HD.jpg?fit=1200%2C300&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2021\/11\/Information-Technology-Wallpaper-HD.jpg?fit=1200%2C300&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2021\/11\/Information-Technology-Wallpaper-HD.jpg?fit=1200%2C300&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2021\/11\/Information-Technology-Wallpaper-HD.jpg?fit=1200%2C300&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3003,"url":"https:\/\/hardsoftsecurity.es\/index.php\/2023\/05\/20\/hack-the-box-busqueda-write-up\/","url_meta":{"origin":3706,"position":4},"title":"Hack The Box | Busqueda | Write UP","author":"david","date":"mayo 20, 2023","format":false,"excerpt":"Hey there, Cyber Warriors! \ud83d\ude80 Guess what? I recently had a wild ride with the Busqueda CTF challenge and I can't wait to share the adventure with you. This challenge was a real treat, pushing my skills and making me think on my feet. It's got everything: sneaky vulnerabilities, cool\u2026","rel":"","context":"En \u00abGu\u00edas\u00bb","block_context":{"text":"Gu\u00edas","link":"https:\/\/hardsoftsecurity.es\/index.php\/category\/guias\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2023\/05\/image.png?fit=1200%2C627&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2023\/05\/image.png?fit=1200%2C627&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2023\/05\/image.png?fit=1200%2C627&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2023\/05\/image.png?fit=1200%2C627&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2023\/05\/image.png?fit=1200%2C627&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3638,"url":"https:\/\/hardsoftsecurity.es\/index.php\/2024\/01\/25\/como-usar-sqlmap-guia-con-caso-practico\/","url_meta":{"origin":3706,"position":5},"title":"\u00bfC\u00f3mo usar SQLMap? Gu\u00eda con caso pr\u00e1ctico.","author":"david","date":"enero 25, 2024","format":false,"excerpt":"\u00a1Hola! Hoy vamos a sumergirnos en el fascinante mundo de SQLMap, una herramienta indispensable para aquellos que se dedican a garantizar la seguridad de las bases de datos y, por supuesto, para los curiosos del pentesting. Imagina tener una navaja suiza que puede detectar y explotar vulnerabilidades en bases de\u2026","rel":"","context":"En \u00abGu\u00edas\u00bb","block_context":{"text":"Gu\u00edas","link":"https:\/\/hardsoftsecurity.es\/index.php\/category\/guias\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/01\/image-2.png?fit=724%2C362&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/01\/image-2.png?fit=724%2C362&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/01\/image-2.png?fit=724%2C362&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/01\/image-2.png?fit=724%2C362&ssl=1&resize=700%2C400 2x"},"classes":[]}],"jetpack_likes_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/hardsoftsecurity.es\/wp-content\/uploads\/2024\/09\/image-1.png?fit=800%2C418&ssl=1","_links":{"self":[{"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/posts\/3706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/comments?post=3706"}],"version-history":[{"count":1,"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/posts\/3706\/revisions"}],"predecessor-version":[{"id":3709,"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/posts\/3706\/revisions\/3709"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/media\/3708"}],"wp:attachment":[{"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/media?parent=3706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/categories?post=3706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hardsoftsecurity.es\/index.php\/wp-json\/wp\/v2\/tags?post=3706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}