<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gaurav Gupta on Medium]]></title>
        <description><![CDATA[Stories by Gaurav Gupta on Medium]]></description>
        <link>https://medium.com/@gdgupta11?source=rss-e4b4ea7eb6ad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6U-l2eePB-LbGFA4YO4lSQ.png</url>
            <title>Stories by Gaurav Gupta on Medium</title>
            <link>https://medium.com/@gdgupta11?source=rss-e4b4ea7eb6ad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 23:31:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gdgupta11/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Phishing resistant solution — FIDO2]]></title>
            <link>https://medium.com/age-of-awareness/phishing-resistant-solution-fido2-2f6624ecf064?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f6624ecf064</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[fido]]></category>
            <category><![CDATA[phishing]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Fri, 21 Nov 2025 16:26:39 GMT</pubDate>
            <atom:updated>2025-11-21T16:26:39.557Z</atom:updated>
            <content:encoded><![CDATA[<h3>Phishing resistant solution — FIDO2</h3><h3>What is phishing ?</h3><p>In easy terms, it is a cyber crime where attackers send malicious emails or messages which appears to be originating from legitimate source. The purpose of these attacks is to get your credentials to access you data/network/environment or implant malware or steal your money or simply just harm the organization with ransomware or extortion.</p><p>Phishing is now considered one of the most common form of cybercrime globally and still most successful way of hacking people. There is an estimate that there are around 3.4 billion phishing emails sent daily which makes up to trillion email annually.</p><h3>Some facts about phishing</h3><ul><li><strong>Unique phishing sites:</strong> In 2024 third quarter alone, over 900,000 unique phishing sites were detected worldwide and making it increase from previous quarter.</li><li><strong>Overall increase in phishing attacks:</strong> According to zscaler 2024 phishing report, phishing attacks surged by 58% in 2023 compared to 2022. This report was made after analyzing more than 2 billion phishing reports. Researchers has seen large increase in new methods of phishing attacks like smishing, vishing and even deep fake attacks rising recently.</li></ul><p>Organizations have been trying hard to prevent their employees fall prey to phishing attacks but attacker always find innovative ways to fooling people and bypassing security controls. Firewalls, Phishing prevention applications, automations and so many other efforts are in place yet thousands of employees fall prey to business email compromise every days.</p><p>This leads to serious consequences to the corporates and even in many cases we have seen very famous compromise cases.</p><p>It is not that there is no reliable solutions are available. Some might argue that 2fa authenticators, push notifications are available which definitely provides some resistance but they are not fully protection proof.</p><ul><li>Authenticators do provide strong second layer protection but AiTM kinds of attack lure people to give away their 2FA authenticators as well.</li><li>Push notifications are good way to know which place the request originated but attackers also found a way like push notification fatigue to bypass these factors.</li></ul><p>So what we need is a strong phishing resistant solution which does not fail and is reliable and pushes back attacker to solve our basic problem of proving the identity and provide authentication.</p><p>so what we go in the store ? FIDO2 !!!</p><h3>Let’s look at FIDO2 now !</h3><p>FIDO (Fast Identity Online) protocols are designed to provide strong, phishing-resistant authentication, addressing attacks like AiTM (Adversary-in-the-Middle) scenarios, including Evilginx2, Modlishka, and Muraena.</p><p>The basic technology behind FIDO is asymmetric cryptography for authentication. During registration a unique key pair is generated.</p><ul><li>The private keys remains security stored on the user’s device</li><li>The public key is shared with the provider.</li></ul><p>During authentication, the private key signs a challenge sent by the service provider, which server verifies with the stored public key.</p><p>FIDO primarily prevents users from AiTM kinds of attacks which is one of the most prevalent way of attacks these days.</p><h3>Key features of FIDO2</h3><p><strong>Domain binding:</strong></p><ul><li>The authentication process is cryptographically bound to the legitimate domain (e.g., <a href="https://login.microsoftonline.com)./">https[://]login[.]microsoftonline[.]com)</a></li><li>Even if the attacker proxies your login request to their phishing domain, the signature verification will fail because the phishing domain does not match the legitimate domain for which the key was created.</li></ul><p><strong>Device Binding</strong>:</p><ul><li>FIDO authentication occurs directly on the user’s trusted device (via a hardware key, platform authenticator, or biometric-enabled device).</li><li>It ensures the authentication process cannot be easily redirected or hijacked to another device controlled by an attacker.</li></ul><p><strong>Protection Against Replay Attacks</strong>:</p><ul><li>The FIDO challenge-response mechanism uses a unique challenge for every authentication attempt. Replay of previously captured challenges is ineffective.</li></ul><p>The best way to learn is through example — lets look at how AiTM attacks happens and how it is prevented with FIDO</p><p>Example scenario when FIDO is not used</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*gE35ioMTL7VeaOKcdLQhPA.png" /><figcaption>Phishing flow when 2FA is not implemented</figcaption></figure><p>In general case when authentication is done</p><ul><li>User clicks on the phishing link → redirected to the phishing domain.</li><li>The phishing domain is proxy domain which relays your request to the original domain intercepting all your creds and other stuff</li><li>User gives away their credentials → User is being redirected to provide 2FA authentication code.</li><li>User puts their 2FA code from their authenticator device that is intercepted by the proxy.</li><li>User is being redirected to the random website and attackers immediately uses the 2FA code and creds to login impersonating you on the website.</li></ul><p>Example scenario when FIDO is used</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*ZIZhVInz0xOPq7BjWAOQew.png" /><figcaption>Example when FIDO 2 is used</figcaption></figure><h4>Step 1: You Click on the Phishing Link</h4><ul><li>You visit a phishing page (https[://]phishingsite[.]com) that mimics Office365.</li></ul><h4>Step 2: You Enter Credentials</h4><ul><li>The phishing page collects your <strong>username</strong> and <strong>password</strong> and forwards them to the real Office365 login page via the attacker’s proxy (Evilginx2/Modlishka/Muraena).</li><li>The attacker successfully proxies the login and reaches the real Office365 2FA prompt.</li></ul><h4>Step 3: Office365 Requests FIDO Authentication</h4><ul><li>When prompted for FIDO-based 2FA:</li></ul><ol><li><strong>Challenge Sent</strong>: The legitimate Office365 server sends a cryptographic challenge to your FIDO authenticator.</li><li><strong>Authenticator Verifies Domain</strong>: Your FIDO authenticator verifies that the challenge originated from https[://]login[.]microsoftonline[.]com, not <a href="https://phishingsite.com./">https[://]phishingsite[.]com.</a></li><li><strong>Phishing Domain Mismatch</strong>: Since the phishing domain does not match the bound domain, the authenticator refuses to sign the challenge, stopping the authentication process.</li></ol><h4>Step 4: Authentication Fails</h4><ul><li>Even if the attacker proxies the entire exchange, the cryptographic signature required for completing FIDO authentication cannot be generated for the phishing domain.</li><li>The attacker cannot bypass this restriction, preventing them from obtaining a session token or completing the login.</li></ul><p><strong>References:</strong></p><ul><li><a href="https://www.zscaler.com/blogs/security-research/phishing-attacks-rise-58-year-ai-threatlabz-2024-phishing-report">2024 Zscaler phishing report</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f6624ecf064" width="1" height="1" alt=""><hr><p><a href="https://medium.com/age-of-awareness/phishing-resistant-solution-fido2-2f6624ecf064">Phishing resistant solution — FIDO2</a> was originally published in <a href="https://medium.com/age-of-awareness">Age of Awareness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic python packaging via github actions]]></title>
            <link>https://gdgupta11.medium.com/basic-python-packaging-via-github-actions-435d0c67813c?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/435d0c67813c</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[python-packages]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Sat, 27 Apr 2024 04:56:17 GMT</pubDate>
            <atom:updated>2024-04-27T04:56:17.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Image generated via AI" src="https://cdn-images-1.medium.com/max/1024/1*l_MQh0NnCpLx4RsC55by8w.jpeg" /><figcaption>Image generated via AI</figcaption></figure><p>When you are building the python or any application, the end goal is always to run these applications in production with all dependencies so that you don’t have install and worry about that one by one.</p><p>In this story, we will continue to explore the application that we created in <a href="https://ggroot.co.in/dockerizing-flask-app-with-mongo-part-2-ca441b825b87">last series</a> which creates a simple profile page and updates the details in the mongo db.</p><p>Here are we are going to:</p><ol><li>Package the python application locally on our laptop.</li><li>Push the changes to github.</li><li>Configure the github actions to package python with all dependencies as soon as there is pull or push request.</li><li>Explore the package artifact and see how we can download it and use it.</li></ol><h4>Package the python app locally on our laptop</h4><p>This is the code that we have checked out locally and we are packaging</p><p><a href="https://github.com/gdgupta11/flaskapp/blob/main/flaskapp/app.py">flaskapp/flaskapp/app.py at main · gdgupta11/flaskapp</a></p><p>After checking out the code locally, lets create the primary requirement of installing setuptools pip install python3-setuptools and we later will put this in requirements.txt file</p><p>Create a file called setup.py in root directory</p><pre># A python setup file for creating python package<br><br>from setuptools import setup, find_namespace_packages<br><br>setup(<br>    name=&#39;flaskapp&#39;,<br>    packages=find_namespace_packages(),<br>    include_package_data=True,<br>    install_requires=[<br>        &#39;Flask&#39;,<br>        &#39;pymongo&#39;<br>    ],<br>    entry_points={<br>        &#39;console_scripts&#39;: [<br>            &#39;flaskapp = flaskapp.app:run&#39;,<br>        ],<br>    },<br>)</pre><p>In the above file first we are importing setuptools and its function to create package and find namespaces incase there are multiple files spread across different folders.</p><p>The file is pretty straight forward, first we define the name, allow it to find all the files across directories, then we mention dependencies that we want to package along. Then in the last we define the entry point of the application which allows our application.</p><p>So when this package is created, we will be able to install this as a pip package and then directly run it using flask run when proper environment variables are set.</p><p>We also need to create another file called MANIFEST.in in root directory with following text. It allows to recursively add all the folders including templates and its html contents. You can do that for other static files as well that you want as part of package.</p><pre>recursive-include flaskapp/templates *</pre><p>We need to build the package using python setup.py sdist</p><pre>(.venv) admin@LAPTOP-3111ode~/code/flaskapp$ python setup.py sdist<br>running sdist<br>running egg_info<br>writing flaskapp.egg-info/PKG-INFO<br>writing dependency_links to flaskapp.egg-info/dependency_links.txt<br>writing entry points to flaskapp.egg-info/entry_points.txt<br>writing requirements to flaskapp.egg-info/requires.txt<br>writing top-level names to flaskapp.egg-info/top_level.txt<br>reading manifest file &#39;flaskapp.egg-info/SOURCES.txt&#39;<br>writing manifest file &#39;flaskapp.egg-info/SOURCES.txt&#39;<br>warning: sdist: standard file not found: should have one of README, README.rst, README.txt, README.md<br><br>running check<br>creating flaskapp-2.0<br>creating flaskapp-2.0/flaskapp<br>creating flaskapp-2.0/flaskapp.egg-info<br>creating flaskapp-2.0/tests<br>copying files to flaskapp-2.0...<br>copying setup.py -&gt; flaskapp-2.0<br>copying flaskapp/__init__.py -&gt; flaskapp-2.0/flaskapp<br>copying flaskapp/app.py -&gt; flaskapp-2.0/flaskapp<br>copying flaskapp.egg-info/PKG-INFO -&gt; flaskapp-2.0/flaskapp.egg-info<br>copying flaskapp.egg-info/SOURCES.txt -&gt; flaskapp-2.0/flaskapp.egg-info<br>copying flaskapp.egg-info/dependency_links.txt -&gt; flaskapp-2.0/flaskapp.egg-info<br>copying flaskapp.egg-info/entry_points.txt -&gt; flaskapp-2.0/flaskapp.egg-info<br>copying flaskapp.egg-info/requires.txt -&gt; flaskapp-2.0/flaskapp.egg-info<br>copying flaskapp.egg-info/top_level.txt -&gt; flaskapp-2.0/flaskapp.egg-info<br>copying tests/tests.py -&gt; flaskapp-2.0/tests<br>copying flaskapp.egg-info/SOURCES.txt -&gt; flaskapp-2.0/flaskapp.egg-info<br>Writing flaskapp-2.0/setup.cfg<br>creating dist<br>Creating tar archive<br>removing &#39;flaskapp-2.0&#39; (and everything under it)</pre><p>This will create dist folder and under that you will find the tar package which you can install it as pip directly</p><pre>(.venv) admin@LAPTOP-3111ode~/code/flaskapp$ ls -ltr dist/<br>total 4<br>-rw-r--r-- 1 spiderman spiderman 2597 Apr 27 09:30 flaskapp-2.0.tar.gz<br>(.venv) admin@LAPTOP-3111ode~/code/flaskapp$</pre><p>When you do pip install flaskapp2-0.tar.gz your application will be installed as python package that you can directly run.</p><pre>(.venv) admin@LAPTOP-3111ode~/code/flaskapp$ pip list |grep -i flaskapp<br>flaskapp     0.0.0<br><br>Export the flaskapp.app variable that can be found when you do flask run<br><br>(.venv) admin@LAPTOP-3111ode~/code/flaskapp$ export FLASK_APP=flaskapp.app</pre><pre>(.venv) admin@LAPTOP-3111ode~/code/flaskapp$ flask run<br> * Serving Flask app &#39;flaskapp.app&#39;<br> * Debug mode: off</pre><p>Later when you define your application to run as systemd service, you can define the variables and starting point flask run or gunicorn in the systemd service file.</p><h4>Push the changes to github.</h4><p>Here is how it will look like: <a href="https://github.com/gdgupta11/flaskapp/tree/main">https://github.com/gdgupta11/flaskapp/tree/main</a></p><h4>Configure the github actions to package python</h4><p>What is Github actions ?</p><p>Github actions is feature provided by Github that allows us to automate tasks and workflows in our repository. There are various and large number of different workflows which are already available and can be directly used. These workflows or actions get triggered when certain event happens or files get pushes or comments being added. There are hundreds of possibles and automation that can be done with github actions like creating python package on push or pull, adding labels on certain comments, creating docker image and pushing into dockerHub, checking python lint, java packaging related actions and many more. See the example picture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vY2cYs_zZR4-p9tx_sLcbQ.png" /><figcaption>Various actions to choose from and it is already available as template. Just have to make small changes</figcaption></figure><p>We will select “Python Package” workflow and get started with it. There are some small changes that you might have to do according to your package.</p><p>In your root directory you have to create .github/workflows/python-package.yaml file and add following code.</p><pre># This workflow will install Python dependencies, run tests and lint with a variety of Python versions<br># For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python<br><br>name: Python package<br><br>on:<br>  push:<br>    branches: [ &quot;main&quot; ]<br>  pull_request:<br>    branches: [ &quot;main&quot; ]<br><br>jobs:<br>  build:<br><br>    runs-on: ubuntu-latest<br>    strategy:<br>      fail-fast: false<br>      matrix:<br>        python-version: [&quot;3.9&quot;, &quot;3.10&quot;, &quot;3.11&quot;]<br><br>    steps:<br>    - uses: actions/checkout@v3<br>    - name: Set up Python ${{ matrix.python-version }}<br>      uses: actions/setup-python@v3<br>      with:<br>        python-version: ${{ matrix.python-version }}<br>    - name: Install dependencies<br>      run: |<br>        python -m pip install --upgrade pip<br>        python -m pip install flake8 pytest<br>        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi<br>    - name: Lint with flake8<br>      run: |<br>        # stop the build if there are Python syntax errors or undefined names<br>        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics<br>        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide<br>        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics<br>    - name: Build Package<br>      run: |<br>        mkdir dist<br>        python setup.py sdist -d dist<br>    - name: Publish Artifact<br>      uses: actions/upload-artifact@v2<br>      with:<br>        name: python-package<br>        path: dist</pre><p>The context of above file is quite simple, we are naming the flow as python package and telling the action to run on push and pull activity in the package. Then, we are telling github to use ubuntu as the build server and build the package on 3.9, 3.10, 3.11 python versions on the build server. We have defined the python versions as array which we are going to iterate in next line.</p><p>After this, we will tell GHA (shortform of Github actions) to follow steps on our package like</p><ul><li>Checkout the package</li><li>Install dependencies mentioned in requirements.txt file using PIP.</li><li>Then we are asking GHA to check for any linting errors and for some serious ones stop the build and throw error. This is fully customizable, you can remove this completely if you want.</li><li>Later we are building the package and telling GHA to follow the steps like create directory and then build package in dist c directory.</li><li>Finally we are asking GHA to push the artifact package (The TAR file) on github artifact which we can download and will be available in dist folder in the github build run summary.</li></ul><p>This is how all build actions looks like when any push or pull event happens</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-DaVO6UIhuiWgMhbu6biMA.png" /><figcaption>All builds on the GHA that ran through our python package yaml file</figcaption></figure><p>when you go on one of these successful builds, and click summary on right side, you will be able to see the artifact available for download at the bottom. See the image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LtAFV_j9AwBr_6JWkW4d7Q.png" /><figcaption>Python package that is build using GHA is available to download</figcaption></figure><p>Once you download it, you can define the environment variable, use pip3 install flaskapp and viola !! your application is running.</p><p>For the above code to run, you need to have mongodb installed as dependency. Look at <a href="https://ggroot.co.in/dockerizing-flask-app-with-mongo-part-2-ca441b825b87">this story</a> to install mongodb.</p><p>Happy learning !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=435d0c67813c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dockerizing flask app with mongo — Part 2]]></title>
            <link>https://gdgupta11.medium.com/dockerizing-flask-app-with-mongo-part-2-ca441b825b87?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca441b825b87</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Thu, 25 Apr 2024 18:38:38 GMT</pubDate>
            <atom:updated>2024-04-25T18:38:38.052Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*F-knqhAm-y75pN4kYx-HkA.png" /><figcaption>Image generated from AI</figcaption></figure><h3>Dockerizing flask app with mongo — Part 2</h3><p>So we wrote this <a href="https://ggroot.co.in/tutorial-for-creating-a-small-python-app-and-dockerizing-it-175ab58c4aff">story last time</a> in which we saw how we created a small python flask app and build that image locally to run that with all the dependencies packaged along with it in the container.</p><p>In this story I am gonna extend the application to add a simple profile fields in the HTML page and add support of pymongo database to the application.</p><p>So we are going to create a 3 fields profile page, which is going to show name, company, address and when you submit it adds that in the database. If you update any field, it overwrites for the existing user it fetched. Also, we are going to manage our mongo db using mongo-express.</p><p>Everything above is going to running in docker containers and we will spun up entire things using docker compose file.</p><p>Let’s get started</p><p>App.py is the primary file where we are putting all our code</p><pre>&quot;&quot;&quot;<br>This is the primary flask application file which is used to create a web application to interact with the MongoDB database.<br>Whie starting the application, it will connect to the MongoDB database and create a connection to the profile database.<br><br>The application will have two routes:<br>1. / - This route will display the existing records in the users collection of the profile database.<br>2. /update - This route will be used to update the existing records in the users collection of the profile database.<br><br>While starting docker container, you can use the following command:<br>docker run -d -p 8080:8080 -v d:/logs:/var/log --net testnet --name flaskapp flaskapp:2.0<br><br>This will connect to the mongo DB container and create a connection to the profile database.<br><br>&quot;&quot;&quot;<br><br>from flask import Flask, render_template, request, redirect, url_for<br>from pymongo import MongoClient<br>import logging<br>import uuid<br><br>app = Flask(__name__)<br><br># Configure logging<br># when using locally, change the log_file path to local path like d:/logs/app.log<br>log_file = &quot;/var/log/app.log&quot;<br>logging.basicConfig(filename=log_file, level=logging.DEBUG, format=&#39;%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s&#39;)<br><br><br># MongoDB connection string<br># Replace &#39;test_database&#39; with your database name, incase of running application outside docker container, <br># use localhost:27017 instead of mongo<br>mongo_uri = &quot;mongodb://admin:apollo13@mongo/&quot; <br>client = MongoClient(mongo_uri)<br>db = client.profile<br>collection = db.users<br><br><br>@app.route(&#39;/&#39;)<br>def index():<br>    contacts = collection.find_one()<br>    logging.info(&quot;Retrieved contacts: %s&quot;, contacts)<br>    return render_template(&#39;index.html&#39;, contacts=contacts)<br><br><br>@app.route(&#39;/update&#39;, methods=[&#39;POST&#39;])<br>def update():<br>    name = request.form.get(&#39;name&#39;).strip()<br>    address = request.form.get(&#39;address&#39;).strip()<br>    company = request.form.get(&#39;company&#39;).strip()<br>    userid = request.form.get(&#39;userid&#39;).strip()<br>    <br>    uid = &quot;None&quot;<br>    item_details = collection.find({&quot;userid&quot;: userid })<br>    for item in item_details:<br>        uid = item[&#39;userid&#39;]<br>    if uid != &quot;None&quot;:<br>        logging.info(f&quot;Updating existing user with unique: {uid}&quot;)<br>        collection.update_one({&#39;userid&#39;: userid}, {&#39;$set&#39;:{&quot;name&quot;: name, &quot;address&quot;: address, &quot;company&quot;: company}}, upsert=True)<br>    else:<br>        # create a random UUID <br>        userid = str(uuid.uuid4())<br>        logging.info(f&quot;Creating new user with following details  - {userid}, {name}, {address}, {company} &quot;)  <br>        collection.insert_one({&#39;userid&#39;: userid, &#39;name&#39;: name, &#39;address&#39;: address, &#39;company&#39;: company})<br>        logging.info(f&quot;New document inserted successfully! userid: {userid}&quot;)<br>    return redirect(url_for(&#39;index&#39;))<br><br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(host=&#39;0.0.0.0&#39;, port=8080, debug=True)</pre><p>Added extensive notes in each file to make it self explanatory, but still lets look what we are doing.</p><p>First after importing all required libraries, I have created a logger to log all our activities and errors into the file for better reading or troubleshooting incase application does not work.</p><p>Later, we are creating mongo DB connection with “profile” as database and “users” a table (which is called collection).</p><p>In this I am assuming that we have only single record so I am fetching that record in app.route(‘/’) and then using that to show existing profile on the index.html page</p><pre>@app.route(&#39;/&#39;)<br>def index():<br>    contacts = collection.find_one()<br>    logging.info(&quot;Retrieved contacts: %s&quot;, contacts)<br>    return render_template(&#39;index.html&#39;, contacts=contacts)</pre><p>Then we are writing the update logic which need little bit more work as we have to first get all the data from our index page, and see if this is a new user or existing one. If existing, then we need to update it else we will create new user entry in our users table.</p><pre>@app.route(&#39;/update&#39;, methods=[&#39;POST&#39;])<br>def update():<br>    name = request.form.get(&#39;name&#39;).strip()<br>    address = request.form.get(&#39;address&#39;).strip()<br>    company = request.form.get(&#39;company&#39;).strip()<br>    userid = request.form.get(&#39;userid&#39;).strip()<br>    <br>    uid = &quot;None&quot;<br>    item_details = collection.find({&quot;userid&quot;: userid })<br>    for item in item_details:<br>        uid = item[&#39;userid&#39;]<br>    if uid != &quot;None&quot;:<br>        logging.info(f&quot;Updating existing user with unique: {uid}&quot;)<br>        collection.update_one({&#39;userid&#39;: userid}, {&#39;$set&#39;:{&quot;name&quot;: name, &quot;address&quot;: address, &quot;company&quot;: company}}, upsert=True)<br>    else:<br>        # create a random UUID <br>        userid = str(uuid.uuid4())<br>        logging.info(f&quot;Creating new user with following details  - {userid}, {name}, {address}, {company} &quot;)  <br>        collection.insert_one({&#39;userid&#39;: userid, &#39;name&#39;: name, &#39;address&#39;: address, &#39;company&#39;: company})<br>        logging.info(f&quot;New document inserted successfully! userid: {userid}&quot;)<br>    return redirect(url_for(&#39;index&#39;))</pre><p>Once this done, we need to update our requirements.txt file in root directory with added dependency</p><pre>Flask==3.0.2<br>pymongo==4.6.3</pre><p>You get get this with simple pip list &gt; requirements.txt</p><p>There is no change in our docker file as entry point and dependencies are same. We just updated our requirements.txt file. So we can go ahead and build it as we did last time.</p><p>Let’s name it flaskapp:2.0 this time.</p><pre>docker build -t flaskapp:2.0 .</pre><p>Once the build is complete we have to manually bring up the pieces to see if they are working and then we create a docker compose file.</p><p>We also have to create a network to ensure that all of our applications are running in same network</p><pre>docker network create testnet</pre><p>Bring up docker for our DB’s first.</p><p>To Spawn a mongo DB latest container:</p><pre>docker run -d -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=apollo13 --net testnet - name mongo mongo</pre><p>Also, I have spawned up a mongo-express container to view the data in the mongo DB.</p><pre>docker run -d -p 8081:8081 -e ME_CONFIG_MONGODB_ADMINUSERNAME=admin -e ME_CONFIG_MONGODB_ADMINPASSWORD=apollo13 -e ME_CONFIG_MONGODB_SERVER=mongo --net testnet --name mongo-express mongo-express</pre><p>What we are doing is pretty simple, just have to ensure that we provide the required environment variables as we have discussed last time. This time in mongoDB and mongo-express we are providing username, password and server name as environment variables along with network name. Nothing fancy here.</p><p>We already have our flaskapp:2.0 image build and ready, lets roll</p><pre>docker run -d -p 8080:8080 -v d:/logs:/var/log --net testnet --name flaskapp flaskapp:2.0</pre><p>One thing is that, I am mapping the d:/logs to /var/log to have persistent logs even if container is deleted.</p><p>Next, you need to visit http://localhost:8081 to see mongodb UI using admin:pass credentials or mentioned when mongo-express comes up.</p><p>Create a database called profile and collection called users</p><p>Now, run your flask application on http://locahost:8080 — You should be able to see the profile empty page. You can go ahead and fill it up and submit.</p><p>Once this testing is successful, lets create a docker compose file to bring up all these components together.</p><p>Create a file called docker compose in root directory and use the below code. One thing that I haven’t mention is to upload your flaskapp image to dockerhub repo.</p><p>I have created a repo in my dockerhub and upload flask image there available publicly. I will create another story to mention how to do that.</p><pre>version: &#39;3.1&#39;<br><br>services:<br>  flaskapp:<br>    image: gg951x/learnings:2.0<br>    ports:<br>      - 8080:8080<br>    restart: always<br>    volumes:<br>      - d:/logs:/var/logs<br>    networks:<br>      - flasknet<br>  mongo:<br>    image: mongo<br>    ports:<br>      - 27017:27017<br>    restart: always<br>    environment:<br>      MONGO_INITDB_ROOT_USERNAME: admin<br>      MONGO_INITDB_ROOT_PASSWORD: apollo13<br>    volumes:<br>      - mongo_data:/data/db<br>    networks:<br>      - flasknet<br>  mongo-express:<br>    image: mongo-express    <br>    ports:<br>      - 8081:8081<br>    restart: always<br>    environment:<br>      ME_CONFIG_MONGODB_ADMINUSERNAME: admin<br>      ME_CONFIG_MONGODB_ADMINPASSWORD: apollo13<br>      ME_CONFIG_MONGODB_SERVER: mongo<br>    networks:<br>      - flasknet<br><br>volumes:<br>  mongo_data:<br>    driver: local<br><br>networks:<br>  flasknet:<br>    driver: bridge</pre><p>In the above docker-compose file you will see that we are bringing up all the components up. All the things we have mentioned in the command line are list written here to ensure things are up and running along with all environment variable. How to bring this up together ?</p><p>Quite simple, just mention below command and it will bring up all the pieces together and application should started connecting with the mongo DB as we have already given the path and tested earlier.</p><pre>docker-compose up .</pre><p>For stopping, just mention docker-compose down . and it will tear down everything.</p><p>All of the above code is mentioned here: <a href="https://github.com/gdgupta11/docker_learning/tree/main">https://github.com/gdgupta11/docker_learning/tree/main</a></p><p>The README.md file is pretty much detailed with instructions. Feel free to experiment.</p><p>Happy Learning !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca441b825b87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tutorial for creating a small python app and dockerizing it.]]></title>
            <link>https://gdgupta11.medium.com/tutorial-for-creating-a-small-python-app-and-dockerizing-it-175ab58c4aff?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/175ab58c4aff</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Sun, 31 Mar 2024 16:57:45 GMT</pubDate>
            <atom:updated>2024-03-31T16:59:02.806Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bBh7eLOvfxiwJ2zKHTLRww.jpeg" /><figcaption>Image generated from AI</figcaption></figure><p>I always have lot of focus on learning new concepts which are which are relevant with your current profile. I generally spend lot of time in learning new concepts about Incident Response. Sometime back I wanted to spend more time on learning kubernetes and docker, so I started documenting my journey of learning basics and advance concepts of docker and Kubernetes.</p><p>In this section we will take a look at creating a small python flask web application and then dockerize it, build it and then run our application in local container.</p><p>I am assuming that you are already aware of basic concepts of docker commands and wanted to take it further to build your own images.</p><p>We will be doing following things to from scratch to create a image of python flask application and then run it in docker container with all its dependencies.</p><p>1. Small python flask app which we can trigger in container.</p><p>2. Test the application in local dev environment if that works.</p><p>3. Create a Dockerfile with required dependencies.</p><p>4. Build and run it.</p><p><strong>Basic Flask Application</strong></p><p>Small python flask app with entry point as <a href="http://app.py/">app.py</a>. For building the python flask app we will have following folder structure.</p><pre>your_project/<br>│<br>├── app.py<br>├── templates/<br>│   └── index.html<br>└── requirements.txt</pre><p>App.py</p><p>Nothing fancy here, we are just creating a very basic python flask application here which will render a basic HTML page showing path of current folder and showing the current time.</p><p>One interesting thing we are doing here is setting the application color via environment variable in the docker. We will see later how we can pass these environment variables in while starting the container.</p><pre>import os<br>import datetime<br>from flask import Flask, render_template<br><br>app = Flask(__name__)<br><br>color = os.environ.get(&#39;APP_COLOR&#39;, &#39;#f5f5dc&#39;)<br><br>@app.route(&#39;/&#39;)<br>def main():<br>    return render_template(&#39;index.html&#39;,<br>                           color=color,<br>                           current_directory=os.getcwd(),<br>                           current_time=datetime.datetime.today())<br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(host=&#39;0.0.0.0&#39;, port=8080, debug=True)</pre><p>index.html file — A very basic HTML to render the title, with background color from environment variable and then showing up current working directory and current time.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;Testing application&lt;/title&gt;<br>    &lt;style&gt;<br>        body {<br>            font-family: Calibri, sans-serif;<br>        }<br>        h1 {<br>            text-align: center;<br>        }<br>        .info {<br>            margin-top: 20px;<br>            text-align: center;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body bgcolor=&quot;{{ color }}&quot;&gt;<br>    &lt;h1&gt;Testing Flask Application in Docker &lt;/h1&gt;<br>    &lt;div class=&quot;info&quot;&gt;<br>        &lt;h3&gt;The Current Directory&lt;/h3&gt;<br>        &lt;p&gt;{{ current_directory }}&lt;/p&gt;<br>        &lt;h3&gt;The Current Time&lt;/h3&gt;<br>        &lt;p&gt;{{ current_time }}&lt;/p&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Now once the application is ready, we need to first test in our local environment if this is working or not as expected</p><pre>PS D:\code\app&gt; python .\app.py<br> * Serving Flask app &#39;app&#39;<br> * Debug mode: on<br> <br>WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.<br> * Running on all addresses (0.0.0.0)<br> * Running on http://127.0.0.1:8080<br> * Running on http://192.168.68.59:8080<br><br>Press CTRL+C to quit<br> * Restarting with stat<br> * Debugger is active!<br> * Debugger PIN: 350-285-912</pre><p><strong>Creating dockerfile</strong></p><p>Once we have tested the application locally, it is time to build the docker image.</p><pre># Use an official Python runtime as a parent image<br>FROM python:3.9<br><br># Set the working directory in the container<br>WORKDIR /usr/src/app<br><br># Copy the current directory contents into the container at /usr/src/app<br>COPY . .<br><br># Install any needed packages specified in requirements.txt<br>RUN pip install --no-cache-dir -r requirements.txt<br><br># Make port 8080 available to the world outside this container<br>EXPOSE 8080<br><br># Run app.py when the container launches<br>CMD [&quot;python&quot;, &quot;app.py&quot;]</pre><p>So, what is the above dockerfile doing ? Very simple, it is pulling up basic python 3.9 image from docker hub.</p><p>You should always remember that images in docker are based on other images, that is called layering. Generally, you will see lot of base images of Alpine linux pulled into as base image because it is light weight. If you go on docker hub here and see the dockerfile of python:3.9 you will see that it has also inherited base image of something else.</p><p>Coming back, later we are setting up our base directory where we will be copying our application developed locally into the image during build process.</p><p>“COPY . .” will copy your all application files into the folder “/usr/src/app”. Always remember the folder structure that you have created and then you have to call your application files accordingly.</p><p>Then, we are running and packing up dependencies in the image. That is the primary advantage of docker that docker images run everywhere without any issues because we pack all required dependencies together and ship it. Once you run it, everything will be there.</p><p>exposing the port 8080 for everyone to access it. Lastly, we are triggering our application to run in the container and that allows flask application to run in the docker container.</p><p><strong>Triggering the build</strong></p><p>There is something the important here which you need to remember if you want to push your image to the public or private repository.</p><p>While building the image, you have to give this “tag” “-t” which allows application to distinguish or gives them version incase when you do changes on your application you building them with different version. You must have seen this while pulling or running different docker images as well.</p><pre><br>D:\code\app&gt;docker build -t flaskapp:1.0 .<br>[+] Building 6.6s (10/10) FINISHED                                                                                docker:default<br> =&gt; [internal] load build definition from Dockerfile                                                                        0.0s<br> =&gt; =&gt; transferring dockerfile: 528B                                                                                        0.0s<br> =&gt; [internal] load metadata for docker.io/library/python:3.9                                                               1.9s<br> =&gt; [auth] library/python:pull token for registry-1.docker.io                                                               0.0s<br> =&gt; [internal] load .dockerignore                                                                                           0.0s<br> =&gt; =&gt; transferring context: 2B                                                                                             0.0s<br> =&gt; [1/4] FROM docker.io/library/python:3.9@sha256:5c72dd8986db8c289ad1a6514319c144ed8f72c6dd702873c4358445473b6f54         0.0s<br> =&gt; [internal] load build context                                                                                           0.0s<br> =&gt; =&gt; transferring context: 642B                                                                                           0.0s<br> =&gt; CACHED [2/4] WORKDIR /usr/src/app                                                                                       0.0s<br> =&gt; [3/4] COPY . .                                                                                                          0.1s<br> =&gt; [4/4] RUN pip install --no-cache-dir -r requirements.txt                                                                4.0s<br> =&gt; exporting to image                                                                                                      0.2s<br> =&gt; =&gt; exporting layers                                                                                                     0.2s<br> =&gt; =&gt; writing image sha256:f8f0979cdced22b2374f9aed4bf631a9e4a225c8f3969d6df7170ccda3f2f5b1                                0.0s<br> =&gt; =&gt; naming to docker.io/library/flaskapp:1.0                                                                             0.0s</pre><p>Finally, running the docker image</p><p>So in below command, we are giving the port on the host and port in the docker container. Also, “-d” option allows docker container to run in detached mode.</p><p>We discussed earlier about environment variable option. Here you can see that we are setting up the environment variable “APP_COLOR” in the container itself so that our application will pick it up.</p><pre># Running the docker container from the your application image you have built.<br>docker run -d -p 8080:8080 -e APP_COLOR=&quot;#f0fff4&quot; flaskapp<br><br># You can see that docker container of our custom flask application is running<br><br>D:\code\app&gt;docker ps<br>CONTAINER ID   IMAGE          COMMAND           CREATED       STATUS       PORTS                    NAMES<br>8a397432ee70   flaskapp:1.0   &quot;python app.py&quot;   2 hours ago   Up 2 hours   0.0.0.0:8080-&gt;8080/tcp   stupefied_lumiere</pre><p>How do we check if our environment variable is setup correctly ?</p><p>First run “docker ps” command to get details of the running container and then we run “env” command using “docker exec” command to see if our environment variables are setup correctly.</p><p>As you can see we have done a good job in building a custom application and running it in docker container</p><pre>D:\code\app&gt;docker ps<br>CONTAINER ID   IMAGE          COMMAND           CREATED       STATUS       PORTS                    NAMES<br>8a397432ee70   flaskapp:1.0   &quot;python app.py&quot;   2 hours ago   Up 2 hours   0.0.0.0:8080-&gt;8080/tcp   stupefied_lumiere<br><br>D:\code\app&gt;docker exec stupefied_lumiere env<br>PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin<br>HOSTNAME=8a397432ee70<br>APP_COLOR=&#39;#f5f5dc&#39;<br>LANG=C.UTF-8<br>PYTHON_VERSION=3.9.19<br>PYTHON_PIP_VERSION=23.0.1<br>PYTHON_SETUPTOOLS_VERSION=58.1.0</pre><p><strong>What’s next ?</strong></p><p>So now we have locally build image with us. We can:</p><ol><li>Create a private/public repo in docker hub/AWS ECR or Azure</li><li>Push this image there for publishing this image for anyone to use.</li><li>We can enhance this application to write into mongo DB and then create ecosystem of where your application runs with Database as backend and having persistent data stored in mongo DB containers.</li></ol><p>Thanks for reading ! Keep learning !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=175ab58c4aff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Very basic take on User initialization files]]></title>
            <link>https://gdgupta11.medium.com/very-basic-take-on-user-initialization-files-877581106431?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/877581106431</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[incident-response]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Fri, 25 Aug 2023 03:10:20 GMT</pubDate>
            <atom:updated>2023-08-25T03:10:20.145Z</atom:updated>
            <content:encoded><![CDATA[<p>It is often confusing to understand that what user initialization files linux system runs when a user logs into the system. Generally system admin has pre-defined settings that needs to be enforced for all users or group of users. Later there are customizations done by user for their own like particular shell, autocomplete, some scrips and aliases.</p><p>The first initialization file that is executed when user logs in is /etc/profile, most of the linux platforms this script includes code that executes all the initialization files in the /etc/profile.d directory that end in a “*.sh”. This directory and script is for administrators to execute scripts for all users when they login. After /etc/profile file is executed, the login shell looks in the user home directory for a file ~/.bash_profile, if found execute it else look for ~/.bash_login and the ~/.profile.</p><p>The next execution is ~/.bashrc, the purpose of the file is to serve as a place where each user can put code that will execute every time user opens a new shell. Exporting user specific environment variable, setting aliases can be done here.</p><p>The last is /etc/bash.bashrc script. The purpose of this file is to serve as a place where system administrators can put code that will execute every time this users opens a new shell.</p><p>On login following files run in the order:</p><ol><li>/etc/profile.d/*sh files run</li><li>Then ~/.bash_profile or ~/.bash_login or ~/.profile files run</li><li>Then ~/.bashrc file run.</li><li>Then /etc/bash.bashrc file runs.</li></ol><p>#linux #learning #ggroot #devops #security #infosec</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=877581106431" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ROOTME tryhackme CTF]]></title>
            <link>https://gdgupta11.medium.com/rootme-tryhackme-ctf-13f5b0c262b2?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/13f5b0c262b2</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Fri, 25 Aug 2023 03:03:11 GMT</pubDate>
            <atom:updated>2023-08-25T03:03:11.655Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R9MXdF3nULx_XAc4" /><figcaption>Photo by <a href="https://unsplash.com/@arget?utm_source=medium&amp;utm_medium=referral">Arget</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Small learnings from <a href="https://tryhackme.com/room/rrootme">CTF ROOTME</a> — This is an easy room in tryhackme.</p><p>Note: This is not entire room walkthrough but things I found interesting and important while completing this room. Just noted it down in my own understanding.</p><p>When we want to enumerate list of on a paths where web service is hosted, we can use gobuster as a quick tool to go through it. Gobuster is available in kali linux.</p><p>The list of the word file is also present on the kali linux in the mentioned directory /usr/share/dirbuster/wordlists</p><pre> <br>gobuster dir -u 10.10.54.11 -w /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt</pre><p>Generally when you are enumerating the directories and path, we look for places which can be abused or which might have vulnerability in that that can be taken advantage of, such as upload forms, login screens, search bars etc..</p><p>In this case it was upload form which allowed to upload different images on the platform. What we can try here is to see if we can upload some malicious script and execute because the website is made in PHP, so we know that PHP scripts can be run on the server. Try uploading PHP file directly (might be denied), try uploading txt files (successful).</p><p>On Kali Linux the reverse SHELL script is available which can be used to upload on this form.</p><p>Generally webshells are malicious piece of scripts which are uploaded from frontend part of the website by abusing the flaws and vulnerability in them. Later on execution of the web-shell, they create backdoor for the attacker to come inside and bring in more tools for execution and persistence. Creation of web-shell might give you temporary access on the server with limited privileges. Later you as attacker has to work to elevate those privileges.</p><pre>Location of the webshell <br><br># /usr/share/webshells/php/php-reverse-shell.php<br><br>Since we know that phtml files can be executed on the server<br><br># mv /usr/share/webshells/php/php-reverse-shell.php phpshell.phtml</pre><p>In this ROOTME CTF case since we cannot upload the PHP files, we can upload PHTML files which are essentially same as PHP files but is parsed by PHP engine. This allows web-server to generate dynamic HTML that is displayed in the browser.</p><p>By copying the reverse shell in your home directory and changing the name of the file to say “phpshell.phtml”. This particular reverse shell needs to have configuration where it will call back to create shell for you. The call back is your attack server.</p><ol><li>Go ahead and upload the PHTML web-shell file on the vulnerable upload section.</li><li>Navigate to the 10.10.10.11/uploads section to see if you are seeing that file (This was known from gobuster enumeration we did earlier)</li><li>Now we need to go on the attack server and listen for the incoming connection from nc -lvnp 1234 the port is also mentioned in the configuration that you can change.</li></ol><p>No when your attack server is listening on the port 1234, go ahead and click on the web-shell file that you have uploaded .It will execute and create a connection for you. The shell we get is temporary, we can convert that into bash by again abusing the python which is available on the server.</p><pre>python -c ‘import pty;pty.spawn(“/bin/bash”)’ </pre><p>There was this last task on the server to escalate the privileges to the root and find the final flag.</p><p>Whenever attacker gets access on the machine, they are generally landed in any user account. In current case it was landed as www (apache) user on the machine.</p><p>The next goal in cyberkill chain is to always escalate the privileges on the server so that we can create persistence on the server or try to move lateral after we become root by getting more access on the machine.</p><p>In current case the way to escalate privileges on the machine where you are already present as a user is to find files which have weird or higher permissions. These important files and binaries can be abused to break out to normal user and escalate privileges to the root.</p><p>Lets find the files which are having permissions like setuid and guid or 777 permissions.</p><pre>Will find all the files with setuid bit <br><br>find / -user root -perm /4000 2&gt;/dev/null </pre><p>In our case we found that /usr/bin/python was having setuid bit set which can be abused -</p><p>Context about setuid</p><p>A<strong>llow users to run an executable with the file system permissions of the executable’s owner or group respectively and to change behavior in directories</strong></p><p>In current case the python owner permission was of root.</p><p>Now since we found that this binary can be abused, we can use python to break out the jail to get root.</p><p>GTFOBin is the place where you can find how and what commands attackers use to abuse the normal binaries present on the server. This is the way the attackers doesn’t have to bring their tools but they can use legitimate tools to abuse the server.</p><p>When you look at this place: <a href="https://gtfobins.github.io/gtfobins/python/">https://gtfobins.github.io/gtfobins/python/</a></p><pre>```<br>This example creates a local SUID copy of the binary and runs it to <br>maintain elevated privileges.<br>To interact with an existing SUID binary skip the first command <br>and run the program using its original path.<br>```<br><br>./python -c &#39;import os; os.execl(&quot;/bin/sh&quot;, &quot;sh&quot;, &quot;-p&quot;)&#39;</pre><p>Once you get the root, you can do anything on the server 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13f5b0c262b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSH Algorithms accepted issue on windows putty]]></title>
            <link>https://gdgupta11.medium.com/ssh-algorithms-accepted-issue-on-windows-putty-41d477157427?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/41d477157427</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ssh-keys]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Fri, 23 Jun 2023 04:56:59 GMT</pubDate>
            <atom:updated>2023-06-23T04:56:59.220Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I created a VM on azure for testing purpose and then when I attempted to login on it. I keep getting message of SSH key getting refused and Public key not supported message. So instead of generating keys every time when we create a VM, I have uploaded the keys to azure and use the same key to deploy along with VM. That allows me use same key-pair across testing machines without issues</p><p>But this time keys kept getting denied. Earlier I thought there is issue with my keys.</p><ul><li>Since I could not login on the machine, I attempted to reset the keys with newly generated keys but issue persisted.</li><li>Then from my another linux machine I copied that public key and attempted to login from linux and it succeeded.</li><li>Copied the same keys to windows and again same issue.</li><li>Then since I was already on the box with another keys, I looked in /var/log/auth.log and saw following logs.</li></ul><p>The logs clearly says that ssh-rsa is not present in PubKeyAcceptedAlgorithms … there you go vola !</p><pre>Jun 18 07:10:24 testserver01 sshd[1856]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]<br>Jun 18 07:10:26 testserver01 sshd[1856]: Connection closed by authenticating user azureuser 49.211.11.11 port 34719 [preauth]<br>Jun 18 07:10:42 testserver01 sshd[1859]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]<br>Jun 18 07:10:43 testserver01 sshd[1859]: Connection closed by authenticating user azureuser 49.211.11.11  port 34526 [preauth]</pre><p>Then next step was to add the the ssh-rsa as accepted algorithm in the sshd_config file.</p><pre>azureuser@testserver01:/var/log$ sudo tail -5 /etc/ssh/sshd_config<br>ChallengeResponseAuthentication no<br>PubkeyAcceptedAlgorithms +ssh-rsa<br>azureuser@testserver01::/var/log$</pre><p>This is just a small issue but sometimes troubleshooting take quite lot of time if you are not looking at the right place.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41d477157427" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding basic important processes in Windows]]></title>
            <link>https://gdgupta11.medium.com/understanding-basic-important-processes-in-windows-6bbc9eb49905?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bbc9eb49905</guid>
            <category><![CDATA[winnit]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[lsass]]></category>
            <category><![CDATA[process]]></category>
            <category><![CDATA[windows]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Sat, 11 Feb 2023 14:35:56 GMT</pubDate>
            <atom:updated>2023-02-11T14:35:56.112Z</atom:updated>
            <content:encoded><![CDATA[<h4>Basic important processes in windows</h4><p>For security Incident response engineer windows investigation is day to day job, At-least 50% or more laptop devices in organization are windows. Often we receive issues of malwares, rogue process, PuPs and unwanted softwares running on employees laptop and spend lot of time in identifying if the process is legitimate.</p><p>Having quick understanding about basic important processes and their default location, parent process and behavior will reduce our investigation time and allow us differentiate between good and bad process quickly.</p><p>In the end I am going to make a <strong>Pro Table</strong> to quickly reference once we have understanding about the behavior.</p><p>When We are talking about process in windows.. Process explorer from Sysinternals (<a href="https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer">https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer</a> ) is very helpful to deep dive into all running processes in the system. You need to run this as administrator to get default path/parent process detail.</p><h4>System (Primary process)</h4><p>The first windows important process is always System. The process ID for this System process is always <strong>4 (Four).</strong> Basically This is a special kind of thread that runs only in kernel mode a kernel-mode system thread. System threads have all the attributes and contexts of regular user-mode threads (such as hardware context, priority and so on) but are different in that they run only in kernel-mode executing code loaded in system space. In addition, system threads don’t have a user process address space and hence must allocate any dynamic storage from operating system heaps, such as paged or nonpaged-pool.</p><p>The related file name for system process is ntoskrnl.exe</p><p><strong>Default path and parent process for System process:</strong></p><ul><li>Process ID is always 4 for this process, If this is running under any other process ID then it is quite suspicious.</li><li>The default path of system process is C:\windows\system32\ntsokrnl.exe</li><li>There is no parent process for system process</li><li>Generally it refers to Process (0) which is a non existent process.</li><li>There is only 1 instance of this service. If you find more than one, then other one is definitely suspicious</li><li>This process starts at boot time itself.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*rzGMhk3STzg3cHhc6iH6Jw.png" /><figcaption>Image 2.1 — System process with process ID 4 and when you click on properties, you see more details about it.</figcaption></figure><h4>SMSS.exe (Session Manager Subsystem)</h4><p>This process is also called windows session manager and is responsible for creating new sessions. This is the <strong>first user-mode process started by Kernel</strong></p><p>Basically this subsystem includes win32k.sys (kernel mode), winsrv.dll (user mode) and csrss.exe (user mode). Smss.exe starts csrss.exe (windows subsystem) and wininit.exe in session 0, an isolated windows session for the operating system, and csrss.exe and winlogon.exe for session 1, which is the user session. The first child instance creates child instance in new session, done by smss.exe copying itself into new session and self terminating.</p><p>Under session 0</p><ul><li>smss.exe creates csrss.exe and wininit.exe</li></ul><p>Under session 1</p><ul><li>csrss.exe &amp; winlongon.exe</li></ul><p><strong>Default path and parent process for SMSS.exe</strong></p><ul><li>The parent process for smss is always system (4)</li><li>The default path of the process is \SystemRoot\System32\smss.exe</li></ul><p><strong>How to identify bad from this process ?</strong></p><ul><li>There should be only one instance of the process running in the system.</li><li>The parent process starts the child instance and exit.</li><li>Always check the directory of the exe file from here it is executing.</li><li>The rurnning user is not the system user</li></ul><h4>CSRSS.exe (Client server Runtime process)</h4><p>This is the user mode side of windows subsystem. This process should always be running and is very critical to the system operations. This process is responsible for the wind32 console window and process threat creation and deletion. For each instance of CSRSS.exe csrsrv.dll, basesrv.dll and winsrv.dll are loaded. This process and winlogon.exe are called from smss.exe during start up.</p><p>There are two csrss.exe processes started by smss.exe</p><ul><li>One process should be started under session 0 and another one should be started under session 1 (User mode). The smss.exe process which starts both of these process exits after starting them.</li></ul><p><strong>Default Path and parent process for csrss.exe</strong></p><ul><li>Default path: \SystemRoot\System32\csrss.exe</li><li>Parent process: Created by smss.exe</li><li>User account: Local system</li></ul><p><strong>How to identify bad from this process ?</strong></p><ul><li>There should not be any parent, the parent exits after starting this process</li><li>Rogue process starting with slightly different name</li><li>The user is not system user.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*R1BQVpqqJ0RG-nWAe_cdYg.jpeg" /><figcaption>Image 2.2 — You can see the process hierarchy started</figcaption></figure><h4>Wininit.exe (Windows initialization process)</h4><p>This is responsible for launching services.exe (Service control Manager), lsass.exe (Local security Authority) and lsaiso.exe within session 0. This is a critical windows process that runs in the background along with its child processes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*kPQ0ITmnKNw6HOd9sRbiUw.jpeg" /><figcaption>Image 2.3 — Here you can see two processes started by wininit.exe , services.exe and lsass.exe</figcaption></figure><p>The process lsaiso.exe will only be visible when credential guard is enabled on the system.</p><p><strong>Default path and parent process for wininit.exe</strong></p><ul><li>Default Path: \SystemRoot\System32\wininit.exe</li><li>Parent process: Started by smss.exe</li><li>Number of instances: one (1)</li><li>Starts immediately after boot</li></ul><p><strong>How identify bad from this process:</strong></p><ul><li>There should not be any parent process for this wininit.exe because smss.exe creates this process and exits.</li><li>Spelling mistakes in the processes</li><li>Different default image path</li><li>Not running as SYSTEM</li></ul><h4>Services.exe (wininit.exe → services.exe)</h4><p>This service is known as service control manager or SCM. Its primary responsibility is to handle system services: Loading services, interacting with services and starting or ending services. It maintains a database that can be queried using a windows built-in utility <em>sc.exe</em></p><ul><li>Information regarding services is stored in HKLM\\System\\CurrentControlSet\\Services</li><li>This process also loads device drivers marked as auto-start into memory</li><li>Services.exe is parent to many other processes in the system like</li><li>Svchost.exe</li><li>spoolsv.exe</li><li>msmpeng.exe</li><li>dllhost.exe</li></ul><p><strong>Default path and parent process for wininit.exe</strong></p><ul><li>Default path: C\Windows\System32\services.exe</li><li>Parent: wininit.exe</li><li>This service is started in session 0</li><li>There should be only 1 instance of this service</li></ul><p><strong>How to identify bad from this process ?</strong></p><ul><li>Services.exe parent is different from <strong>wininit.exe</strong></li><li>Different default image path</li><li>Spelling mistake</li><li>Multiple running instances, ideally there should be only one.</li><li>Not Running as SYSTEM</li></ul><h4>SVCHOST.exe (wininit.exe → Services.exe → svchost.exe)</h4><p>This is very generic process in windows which is used to club other processes in the windows. Instead of many different processes having of same type, svchost.exe is used to club them together. This reduces the resource usage on the system. There are lot of services in windows and most of these services are running under one svchost.exe .</p><p>For better manageability and resource usage these are separated out and similar kind of processes are clubbed together</p><p>SVCHOST is used for running service DLLs. One any windows system you will find multiple instances of svchost.exe running at any time. Each of this instance has a <strong>unique </strong><strong>-K parameter</strong> defined.</p><p>The services running in this process are implemented as DLL. The DLL to implement is stored in the registry for the service under the Parameters subkey in ServiceDLL. The full path where service DLL is stored in registry is: HKLM\\system\\CurrentControlSet\\Services\\SERVICE NAME\\Parameters</p><p><strong>Defaut path and parent process of svchost.exe</strong></p><ul><li>The default path of svchost.exe is C:\windows\system32\svchost.exe</li><li>The services.exe is the parent process of svchost.exe</li></ul><p><strong>How to identify bad svchost.exe</strong></p><ul><li>When you are investigating a malware or rogue process on the windows machine. Look for default path where service has been loaded, anything other than %SystemRoot%\System32\svchost.exe should be malicious.</li><li>If you find any svchost.exe process which does not have -K parameters then that is more likely to be malicious and should be investigated further.</li><li>The -k Parameter is for grouping similar services to share the same process. This was as mentioned above to reduce the resource usage.</li><li>Look for service names with wrong spellings.</li></ul><p>How does svchost.exe looks like in task manager ?</p><p>As you can see that this <strong>svchost.exe</strong> has clubbed multiple other services other of same kind.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*vRo5LIL_vw0gQuJjpLEguQ.png" /><figcaption>Multiple services are clubbed into together by svchost.exe</figcaption></figure><p>In another, we can see that there are multiple instances of svchost.exe available at any given time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*pClR5XdM-DLGMljZfjdukA.png" /><figcaption>Multiple instances of svchost.exe which is a normal behavior</figcaption></figure><h4>LSASS.exe (wininit.exe → lsass.exe)</h4><p>Local security Authority Subsystem Service (LSASS) enforces security policy on the system. It verifies user logging on to the windows computer or server, handles password changes, creates access tokens and writes to security event log.</p><ul><li>This service creates token for SAM(Security Account Manager)</li><li>Active Directory</li><li>Netlogon</li></ul><p>This service uses authentication package specified in <strong>HKLM\System\CurrentControlSet\Control\Lsa</strong>. LSASS is frequently targeted with mimikatz tools by attackers to dump all the tokens and password stored in memory in LSASS.exe.</p><p><strong>Default Path and parent process of lsass.exe</strong></p><ul><li>Default Path: %SystemRoot%\System32\lsass.exe</li><li>Parent process: WinInit.exe</li><li>Number of Instances: 1</li></ul><p>Good read about lsass.exe: <a href="https://yungchou.wordpress.com/2016/03/14/an-introduction-of-windows-10-credential-guard/">https://yungchou.wordpress.com/2016/03/14/an-introduction-of-windows-10-credential-guard/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*NAGKrSRLqQBXyAxA_sL5Cg.jpeg" /><figcaption>Image shows that lsass.exe started by wininit.exe and default location</figcaption></figure><h4>winlogon.exe</h4><p>Winlogon.exe is responsible for handling Secure Attention Sequence (SAS). This process is also responsible for loading the user profile. It loads the user NTUSER.DAT into HKEY Current USER and userinit.exe loads the user shell. Winlogon.exe is launched by smss.exe along with csrss.exe in session 1. The smss.exe launches both these processes and exits. That’s why you won’t be seeing any parent process for winlogon.exe. It should always shows as non-existent.</p><p>There are other functions as well which winlogon.exe does</p><ul><li>Responsible for locking screen</li><li>Running screensaver</li></ul><p><strong>Default path and parent process for winlogon.exe</strong></p><ul><li>Default Path: C:\Windows\System32\winlogon.exe</li><li>Parent Process: smss.exe (Exits after starting winlogon.exe and csrss.exe in session 1)</li><li>User: This should always run as SYSTEM user</li></ul><p><strong>How to identify bad winlogon.exe ?</strong></p><ul><li>If there is a parent process for winlogon.exe</li><li>Image path other than C:\Windows\System32\</li><li>Mis-spelling</li><li>Not running as SYSTEM</li></ul><h4>Explorer.exe</h4><p>Explorer.exe is the most common process that every one is aware about. We can access files and folders using explorer and also provides functionality for start menu and task bar.</p><p>Default Path: %SystemRoot%\explorer.exe</p><ul><li>There can be multiple child processes for explorer</li><li><a href="http://explorer.ee/">Explorer.e</a>xe is created by userinit.exe and it exits</li><li>Each explorer.exe should be under current user process</li><li>Spelling mistakes</li><li>Inbound and outbound TCP connections from this process</li></ul><p>So how does the entire above processes relationship look like ? I have created a tree format for parent Child relationship to understand it better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ciVjuYasjrqUGDOBj3Acnw.jpeg" /></figure><p>If you want to look at above tree you can copy paste below created json into jsoncrack and you see pro tree.</p><pre>{<br>  &quot;System.exe&quot;: &quot;First System process, starts at boot time&quot;,<br>  &quot;Parent Process&quot;: &quot;None&quot;,<br>  &quot;Default Path&quot;: &quot;C:\\Windows\\System32&quot;,<br>  &quot;Total Instances&quot;: &quot;1&quot;,<br>  &quot;User Account&quot;: &quot;Should always run under SYSTEM user&quot;,<br>  &quot;System.exe Spawns&quot;: [<br>    {<br>      &quot;SMSS.exe&quot;: &quot;Session Manager Subsystem&quot;,<br>      &quot;Parent Process&quot;: &quot;Always System.exe Process No. 4&quot;,<br>      &quot;Default Path&quot;: &quot;C:\\Windows\\System32\\smss.exe&quot;,<br>      &quot;Child Process 1&quot;: &quot;csrss.exe and wininit.exe in Session 0 (kernel Space)&quot;,<br>      &quot;Child Process 2&quot;: &quot;csrss.exe and winlogon.exe in Session 1 (User Space)&quot;,<br>      &quot;User Account&quot;: &quot;Should always run under SYSTEM user&quot;,<br>      &quot;Malicious Behavior&quot;: &quot;Only 1 Instance, Not running as System, parent process ID different than 4&quot;,<br>      &quot;Smss.exe Spawns&quot;: [<br>        {<br>          &quot;Winlogon.exe&quot;: &quot;Takes care of all things when user logs in&quot;,<br>          &quot;Parent Process&quot;: &quot;Smss.exe in session 1&quot;,<br>          &quot;Properties&quot;: &quot;Loads NTUSER.DAT into HKEY Current User Resitry, Responsible for locking &amp; screensaver&quot;,<br>          &quot;Default Path&quot;: &quot;C:\\Windows\\System32\\winlogon.exe&quot;,<br>          &quot;User Account&quot;: &quot;Should always run under SYSTEM user&quot;,<br>          &quot;Malicious Behavior&quot;: &quot;Different Parent process, Not running as system, Mis-spelling&quot;,<br>          &quot;Winlogon.exe Spwans&quot;: [<br>            {<br>              &quot;Userinit.exe&quot;: &quot;Spaws explorer.exe and exits&quot;,<br>              &quot;Userinit.exe spawns&quot;: [<br>                {<br>                  &quot;explorer.exe&quot;: &quot;Gives user access to their files and folders &quot;,<br>                  &quot;Parent Process&quot;: &quot;Userinit.exe starts explorer.exe and exits&quot;,<br>                  &quot;Default Path&quot;: &quot;C:\\Windows\\explorer.exe&quot;,<br>                  &quot;Other Facts&quot;: &quot;userinit.exe starts shell in HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Shell&quot;,<br>                  &quot;User Account&quot;: &quot;Logged in user context&quot;,<br>                  &quot;Instances&quot;: &quot;Multiple Instances of the process&quot;,<br>                  &quot;Malicious Behavior&quot;: &quot;No Outbound/Inbound TCP, spelling mistakes and Actual parent process&quot;<br>                }<br>              ]<br>            }<br>          ]<br>        },<br>        {<br>          &quot;CSRSS.exe&quot;: &quot;Client Server runtime process (During start up&quot;,<br>          &quot;Parent Process&quot;: &quot;No Parent process, smss.exe spawns and exits in session 0&quot;,<br>          &quot;Default Path&quot;: &quot;C:\\Windows\\System32\\csrss.exe&quot;,<br>          &quot;Child Process/DLLs&quot;: &quot;For each instance of csrss, csrsrv.dll, basesrv.dll and winsrv.dll are loaded&quot;,<br>          &quot;User Account&quot;: &quot;Should always run under SYSTEM user&quot;,<br>          &quot;Malicious Behavior&quot;: &quot;If you see parent of this process, Not started as system user, Mis-spelling&quot;<br>        },<br>        {<br>          &quot;Wininit.exe&quot;: &quot;Windows Initialization Process&quot;,<br>          &quot;Parent Process&quot;: &quot;No Parent process, smss.exe starts and exits&quot;,<br>          &quot;Default Path&quot;: &quot;C:\\Windows\\System32\\wininit.exe&quot;,<br>          &quot;Child Process&quot;: &quot;Services.exe&quot;,<br>          &quot;User Account&quot;: &quot;Should always run under SYSTEM user&quot;,<br>          &quot;Malicious Behavior&quot;: &quot;Is you see parent of this process, Not running as System&quot;,<br>          &quot;Wininit.exe Spawns&quot;: [<br>            {<br>              &quot;LSASS.exe&quot;: &quot;Local Security Authority subsystem service &quot;,<br>              &quot;Properties&quot;: &quot;Verifies User logins, handles password changes, creates access token \n and writes to SecurityEvent log&quot;,<br>              &quot;Default Path&quot;: &quot;C:\\Windows\\System32\\lsass.exe&quot;,<br>              &quot;Other Facts&quot;: &quot;Creates tokens for SAM, Active directory and Netlogon&quot;,<br>              &quot;Instances&quot;: &quot;Always 1&quot;<br>            },<br>            {<br>              &quot;Services.exe&quot;: &quot;Service control Manager (SCM), Load services, Interact with services, start/end services&quot;,<br>              &quot;Regsitry&quot;: &quot;Services info is stored in HKLM\\System\\CurrentControlSet\\Services&quot;,<br>              &quot;Default Path&quot;: &quot;C:\\Windows\\System32\\services.exe&quot;,<br>              &quot;Child processes&quot;: &quot;Svchost.exe, spoolv.exe, msmpeng.exe, dllhost.exe&quot;,<br>              &quot;Other Properties&quot;: &quot;Starts in Session 0 &quot;,<br>              &quot;User Account&quot;: &quot;Should always run under SYSTEM user&quot;,<br>              &quot;Instances&quot;: &quot;Always 1&quot;,<br>              &quot;Malicious Behavior&quot;: &quot;More than 1 instance, Different user&quot;,<br>              &quot;Services.exe Spawns&quot;: [<br>                {<br>                  &quot;Svchost.exe&quot;: &quot;Clubs similar process together to reduce resource usage&quot;,<br>                  &quot;Registry&quot;: &quot;HKLM\\system\\CurrentControlSet\\Services\\SERVICE NAME\\Parameters&quot;,<br>                  &quot;Parent Process&quot;: &quot;Services.exe&quot;,<br>                  &quot;Default Path&quot;: &quot;C:\\Windows\\System32\\svchost.exe&quot;,<br>                  &quot;Other Facts&quot;: &quot;All process starts with -K \\n service running in this are implemented as DLL&quot;<br>                }<br>              ]<br>            }<br>          ]<br>        }<br>      ]<br>    }<br>  ]<br>}</pre><p>I hope this above explanation of parent child relationship of important windows services will be helpful for people starting new in windows. As I have mentioned earlier as well, in IR its very important to understand how does normal behavior looks so that you can identify the anamoly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bbc9eb49905" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How admin shares works in windows]]></title>
            <link>https://gdgupta11.medium.com/how-admin-shares-works-in-windows-353a8aad2f59?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/353a8aad2f59</guid>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[share]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 17:03:44 GMT</pubDate>
            <atom:updated>2023-02-03T17:03:44.637Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>What are administrative shares on windows ?</strong></h4><p>Administrative shares on windows machines are used to <strong>remotely</strong> access and manage the computer/servers. Windows machines might have default admin shares shared but they might be hidden when you are access the machine remotely. You might need to access them differently using UI or command line .</p><p>For command line you can run <strong>net share</strong> command to list of admin shares from this machine.</p><p>If you want to look into UI → Open Computer Management Console (compmgmt.msc) → System tools → Shared folders → Share section. You should be able to see all the admin shares there. If you right click any of them you should be able to options to either disable them or look for more available options like disabling them or view the share</p><h4>How do I identify admin shares ?</h4><p>All the admin shares end with $ (dollar sign). By default this is hidden when you access a remote machine in your network using \\RemoteComputerName. These are SMB resources that are shared with other computers over remote access.</p><figure><img alt="When open Computer Management, you can see all the shares on your computer" src="https://cdn-images-1.medium.com/max/988/1*FL5ejQ2sPNQ0_Q05Lc_2hA.jpeg" /><figcaption>When you open Computer Management, it shows shares for the computer</figcaption></figure><h4>What are the default shares on windows machines ?</h4><ul><li>ADMIN$ — This is the primary %SystemRoot% directory</li><li>C$ — Default drive</li><li>IPC$</li></ul><h4>How to look for admin shares on remote computers ?</h4><pre># Using command line <br><br>net view \\remoteComputerName /all <br><br>#when you are accessing it via explorer you can view in following way <br><br>\\remoteComputerName\c$</pre><p>Admin shares makes the life easy for managing different computers in the network but that also comes with security risk.</p><p>For disabling via UI,</p><ul><li>open regedit.exe and navigate to the location HKLM\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters</li><li>If the key is not present you can create the new key called <strong>AutoShareWks</strong> with type as REG_DWORD and value as 0</li></ul><p>Following command can be used to disable the admin share on the computer . For this user must have local administrator access on the machine</p><pre>#Windows command line <br><br>reg add HKLM\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters /f /v AutoShareWks /t REG_DWORD /d 0<br><br>#Windows powershell<br><br>New-ItemProperty -Name AutoShareWks -Path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters -Type DWORD -Value 0<br><br># Using powershell if you want to change the existing property <br><br>Set-ItemProperty -Name AutoShareWks -Path HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters -Value 1</pre><p>If you have domain joined computer, in that case when you try to access the admin share using user who is part of local administrator group, the access will be denied. You could access the admin share using Administrator user or via domain accounts which are having administrator privileges on the computer.</p><p>This above behavior is controlled by something called Remote user access control for remote connections. This filters out tokens of local and microsoft accounts and blocks remote accesses to admin shares under such accounts. This restriction is not applied in domain joined accounts.</p><p>There is a way to disable Remote user account control by creating LocalAccountTokenFilterPolicy parameter in registry</p><ul><li>Navigate to <strong>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System</strong></li><li>Create a new key — LocalAccountTokenFilterPolicy and set the parameter value to 1;</li></ul><p>or add this via command line</p><pre>reg add &quot;HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System&quot; /v &quot;LocalAccountTokenFilterPolicy&quot; /t REG_DWORD /d 1 /f</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=353a8aad2f59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unfolding of Malwares/Ransomware using Vulnerabilities]]></title>
            <link>https://gdgupta11.medium.com/unfolding-of-malwares-ransomware-using-vulnerabilities-784be57b33e6?source=rss-e4b4ea7eb6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/784be57b33e6</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[ransomware]]></category>
            <dc:creator><![CDATA[Gaurav Gupta]]></dc:creator>
            <pubDate>Thu, 21 Apr 2022 19:55:25 GMT</pubDate>
            <atom:updated>2022-04-21T20:04:04.737Z</atom:updated>
            <content:encoded><![CDATA[<p>I enjoy reading threat reports about the latest malware and ransomware attacks in the market. Below is some basic understanding from various blogs that I read in the last few days related to malware and ransomware.</p><p>Below is the example that during one ransomware attack, how did the entire workflow happen for the attacker. How did they achieve deploying the malware or cred stealer on the active directory. This example is from attack on windows exchange server</p><p><strong>Some of my thoughts about exploitation of vulnerability from IR perspective</strong></p><ul><li>Whenever an exploitation/vulnerability comes out in the market not everyone fixes that in time. Attackers use those kinds of vulnerabilities to go after the victims who have not implemented the immediate fix or did not deploy the patches for the long term fix.</li><li>Attackers do a lot of recon on various websites to gather more and more details about the victim companies. They keep on looking at websites like <a href="http://shodan.io/">shodan.io</a>, <a href="http://github.com/">github.com</a>, domain enumeration and other things to gather details about servers which are impacted with critical vulnerabilities.</li><li>The criticality of the damage depends on the attack surface and the attack scope which keeps on changing on a daily and hourly basis. Assuming that a vulnerability which has just got published by the vendor like MSFT, VMware, solarwinds will prompt clients to run for patching and getting an immediate fix but it will surely happen that within few hours someone will have POC of the vulnerability and post that on <a href="http://github.com/">github.com</a> or <a href="http://bitbucket.com/">bitbucket.com</a>. As soon as that happens, the attack surface changes quickly and now the vulnerability becomes practically exploitable by threat actors, script kiddes, ransomware groups and nation state actors.</li><li>Any vulnerability that is remotely exploitable (RCE), Does not require authentication, Is a zero day vulnerability or something that is supplychain attack which is heavily used in your environment becomes very dangerous and needs immediate fix. If anything which is more than say CVSS score of 9, then it is kind of all hands on the deck and fix it.</li></ul><p><strong>Example of one of the attacks: How generally it unfolds:</strong></p><ul><li>In one of the cases, an attacker used ProxyShell vulnerability on the exchange servers to get access on the exchange servers. This vulnerability was marked as very critical with CVSS 9.8. CVE-2021–34473, CVE-2021–34523, and CVE-2021–31297, and their severity rating ranges from 7.2 (high) to 9.8 (critical).</li><li>Once they got the access, they deployed webshells in the accessible exchange server directory and later they executed powershell code with high privileges to download cobalt strikes malwares.</li><li>The webshells, reverse shells which are dropped on the victim machines are generally available on open repositories on gitbub or many times they use free websites like pastebin with thousands of bins created for each of the requirements which is kind of use and throw thing and very difficult to track.</li><li>Once the attacker has access to the systems, these can be sold off on the dark web to the threat actor groups for further exploitation as they like.</li><li>Attackers once on the systems they will run credential stealer to siphon off creds from the memory mostly using mimikatz and try to get lateral movement access for higher privileges systems.</li><li>The second ultimate goal of the attacker is to get access to domain controllers and get access to the creds for the entire domain. They will keep doing lucrative lateral movements and elevation of privileges.</li><li>The ultimate goal of the attacker is to get data out of the company’s network into this network. Once that is done, it might be called success for them.</li><li>Earlier ransomware groups used to just encrypt the data and ask for ransom from the companies, nowadays, they have changed their strategy, before encrypting the data they exfil the critical data like copyrights materials, code, configurations, files and then they encrypt entire applications and data on the machine.</li><li>Doing these they get double leverage. If somehow companies managed to get backup online with backup restore and DR sites, still they threaten them to pay, else they will leak the copyright and intellectual proprietary data on the dark web.</li><li>They recently did with multiple companies like Nvidia and Microsoft.</li></ul><p><strong>Some of the famous ransomware groups:</strong> REvil, Conti, BlackByte, Cuba, Babuk, LockFile, Hive Ransomware.</p><p>These days you will use ransomware as a service on the darkweb with everything in place, a group of attackers can directly target their victims without breaking a sweat. <strong>They just started using ransomware as a service infra.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=784be57b33e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>