avatarStackZero

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3392

Abstract

   <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*mbPNVywqfuaaJEE0)"></div>
          </div>
        </div>
      </a>
    </div><p id="e117">Here we’ve put together a list of some exciting and unique ideas of how to deal with anxiety when your boyfriend or husband goes out.</p><h1 id="8982">1. Communicate With Your Beloved</h1><figure id="073d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*h_1yJ7rp8mm66RHp"><figcaption>Photo by <a href="https://unsplash.com/@henrihere?utm_source=medium&amp;utm_medium=referral">Henri Pham</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p id="b290" type="7">Falling in love is easy, but the fear of losing someone is more common in females or girls than in males or boys.</p><p id="249e">As you get into a relationship, the things will not always remain the same between both of you. Sometimes, it will bring you lots of happiness, and sometimes you’ll feel depressed and hopeless.</p><div id="b6ba" class="link-block">
      <a href="https://readmedium.com/why-i-once-decided-to-end-my-life-dcaac8108878">
        <div>
          <div>
            <h2>Why I Once Decided To End My Life?</h2>
            <div><h3>My life is full of problems, and I sometimes think of ending my life…</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*2WNkqY43O_jA1dyz)"></div>
          </div>
        </div>
      </a>
    </div><p id="d9f3">The best and most important way to deal with relationship anxiety is calling your boyfriend or husband once a while. If they’re out for some time, you should keep calling them every hour to remind them how much you love them.</p><p id="e1e1">There’s no need to get stressed if your boyfriend or husband remains out for several hours. Maybe, they’ve some urgent works to do. You just have to be polite and speak nicely, make them realize that you care for them and want them to come back as soon as possible.</p><h1 id="4430">2. Exercise Or Brisk Walk</h1><figure id="5179"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*gCB8QQvSvUyoa5wD"><figcaption>Photo by <a href="https://unsplash.com/@liujiao?utm_source=medium&amp;utm_medium=referral">Liu Jiao</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p id="2998">This is not a joke; anxiety is a serious mental condition and that means you’ll have to manage it in any way. Exercise is indeed a good way to control the way you feel.</p><div id="548d" class="link-block">
      <a href="https://readmedium.com/you-dont-need-exercises-to-be-healthy-and-fit-here-s-why-50c6b32a82c7">
        <div>
          <div>
            <h2>You Don’t Need Exercises To Be Healthy And Fit — Here’s Why</h2>
            <div><h3>If you want to be healthy, you don’t need treadmills or weight machines. Let’s check out why…</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*KFpMZA1MPQMIOJtI)"></div>
          </div>

Options

     </div>
      </a>
    </div><p id="52b5" type="7">It has now been proved that brisk walk or exercise is a powerful and comprehensive way to control anxiety symptoms.</p><h1 id="ecb0">3. Start Over</h1><figure id="ebf7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*10VfnKgugxKjc8BW"><figcaption>Photo by <a href="https://unsplash.com/@lgnwvr?utm_source=medium&amp;utm_medium=referral">LOGAN WEAVER</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p id="fa7a">If the trust has gone, you should talk to your partner instantly and start over. Trust and respect are the foundations of a relationship, and if things aren’t going as planned, you’ll have to redo everything needed to strengthen this relationship.</p><div id="d670" class="link-block">
      <a href="https://readmedium.com/not-falling-in-love-is-itself-a-disease-8e7a625a3f9e">
        <div>
          <div>
            <h2>Not Falling In Love Is Itself A Disease</h2>
            <div><h3>If you are afraid of falling in love or getting close to someone, you are probably suffering from a severe…</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*GB2rd4DdJpvTfbX4)"></div>
          </div>
        </div>
      </a>
    </div><p id="9ec6" type="7">It’ll take you weeks or even months to get back to a normal life. At the same time, you should not fall back into old habits.</p><h1 id="033a">4. Stay Mentally Busy</h1><figure id="962e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*p0dj3T0srlmx57bF"><figcaption>Photo by <a href="https://unsplash.com/@mannydream?utm_source=medium&amp;utm_medium=referral">Manny Moreno</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p id="7b97">Being busy will be difficult if your partner is out for many hours. However, you need to do so in order to improve your mood. You can begin reading a book, watch television or cook some food for your beloved.</p><p id="546d" type="7">You should do all the things that can keep your mind off your partner for some time. Gardening is also a good idea, or else, you can play some video games.</p><div id="adc6" class="link-block">
      <a href="https://readmedium.com/the-heart-is-made-to-be-loved-9a747000d9ae">
        <div>
          <div>
            <h2>The Heart Is Made To Be Loved</h2>
            <div><h3>If you think you don’t need anyone to live happily, you are totally wrong…</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*4JJQuCU2xaRgQoYS)"></div>
          </div>
        </div>
      </a>
    </div><p id="abfb">In the end, we’d like to say that you should give them some freedom. Maybe, your partner wants to focus on his career or some other things, so you need to understand their feelings and happily allow them to stay away from you for as much time as they want.</p><h2 id="81cd">What do you do when your boyfriend or husband doesn’t respond to your calls?</h2></article></body>

How to easily encrypt file in Python — StackZero

The idea behind file encrypting in python

In this article, we will create a simple script python that uses XOR to encrypt a file. Xor is one of the most simple encryption methods malware developers use to obfuscate their code thanks to its significant advantages:

  • simplicity (no need for an easy to find external encryption library)
  • minimal length

Given that, it can be hard for an analyst to find, especially in a fast static analysis like string research, import table analysis or shellcode analysis.

Prerequisites

For this mini project the only thing you need is a working installation of python3

What is XOR

The XOR operator is a logical operation that takes two operands and returns a true or false value based on whether the operands are different or the same.

It has the property that XORing two times an operand with the same one, we will have the starting one, it make possible to use this operator for symmetric encryption.

The code

We want to pass a file and XOR it char by char with a number passed in input:

def xor_content(content, key: int):
    return [x ^ key for x in content]
if __name__ == "__main__":
    if len(sys.argv) < 4:
        print("USAGE:")
        print("python3 xor_file.py <KEY> <INPUT_FILENAME> <OUTPUT_FILENAME>")
        exit(0)
    with open(sys.argv[2], "rb") as i_file:
        in_content = i_file.read()
        output = xor_content(in_content, int(sys.argv[1]))
        with open(sys.argv[3], "wb") as o_file:
            o_file.write(bytearray(output))

This code takes in a key and two file names as input. It then reads the first file, xors every byte with the key, and writes the result to the second file.

We can launch it in this way:

python3 main.py 65 input.txt output.txt

Basically, launching that it will xor char by char of the file “ input.txt” with 65 and then write the output onto “ output.txt “.

Improvements

Encrypt a file in python seems really easy, but we can do something more.

The XOR represents a single byte encoding, and due to the fact that a null byte xor with the key, returns the key, we can see a potential weakness. In fact usually there are a lot of null bytes and it can see that the encoded file shows a bunch of bytes equal to the key. The same problem occurs with a byte equal to the key.

The malware author mitigates that using a NULL-preserving single-byte XOR encoding scheme. It simply means to skip NULL bytes and the ones equal to the key. So let’s try to make it, changing the xor_content method:

def xor_content(content, key: int):
    return [x ^ key for x in content if x != key and x != 0]

Bruteforcing XOR encoding

Our work seems to be ok, but it works just if we have found the key in assembly. Now let’s try to code a tool that bruteforces the encrypted file in order to find a specific set of bytes.

First of all we need to write a method that checks if a sub is subarray of arr.

def is_subarray(sub, arr):
    if len(sub) > len(arr):
        return False
    for i in range(len(arr) - len(sub) + 1):
        if arr[i : i + len(sub)] == sub:
            return True
    return False

This code block opens a file and reads its contents into a list. It then uses a for loop to iterate through every possible key value from 1–128. For each key, it xor’s the list of file contents with the key, and converts the result into a string. If the string contains the substring (in hex) passed as third argument, it prints the key and exits the program; otherwise, it prints “Key not found” and exits the program.

Put all together

Now let see the complete code for both scripts

xor_file.py

import sys
def xor_content(content, key: int):
    return [x ^ key for x in content if x != key and x != 0]
if __name__ == "__main__":
    if len(sys.argv) < 4:
        print("USAGE:")
        print("python3 xor_file.py <KEY> <INPUT_FILENAME> <OUTPUT_FILENAME>")
        exit(0)
    with open(sys.argv[2], "rb") as i_file:
        in_content = i_file.read()
        output = xor_content(in_content, int(sys.argv[1]))
        with open(sys.argv[3], "wb") as o_file:
            o_file.write(bytearray(output))

bruteforce.py

def is_subarray(sub, arr):
    if len(sub) > len(arr):
        return False
    for i in range(len(arr) - len(sub) + 1):
        if arr[i : i + len(sub)] == sub:
            return True
    return False
if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("USAGE:")
        print("python3 bruteforce.py <INPUT_FILENAME> <KEY_TO_SEARCH>")
        exit(0)
    with open(sys.argv[1], "rb") as i_file:
        in_content = [x for x in i_file.read()]
        for k in range(1, 128):
            output = xor_content(in_content, k)
            string = [x for x in bytearray.fromhex(sys.argv[2])]
            if is_subarray(string, output):
                print(f"The key is {k}")
                sys.exit(0)
        print("Key not found")

Conclusion

At this point we have all that we need, and we can test it with this simple commands:

python3 xor_file.py 88 in.txt out.txt 
python3 bruteforce.py out.txt 4d5a

If everything is right the output should be:

The key is 88

Note: “4d5a” passed as input in our example is the hexadecimal ASCII value of the initial two bytes of a DOS MZ EXECUTABLE.

This is a technique to hinder static analysis, if you want to know some simple ideas to do the same with dynamic analysis, take a look to those posts:

Originally published at https://www.stackzero.net on May 16, 2022.

Hacking
Python
Xor
Encoding
Cryptography
Recommended from ReadMedium