<?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 Brian Davis on Medium]]></title>
        <description><![CDATA[Stories by Brian Davis on Medium]]></description>
        <link>https://medium.com/@slimm609?source=rss-79382b3fed79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gKT2zgRZW4t1waRm</url>
            <title>Stories by Brian Davis on Medium</title>
            <link>https://medium.com/@slimm609?source=rss-79382b3fed79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:49:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@slimm609/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[The Death of Leetcode? Will Prompt Engineering interviews replace coding interviews?]]></title>
            <link>https://medium.com/@slimm609/the-death-of-leetcode-will-prompt-engineering-interviews-replace-coding-interviews-69d5de787234?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/69d5de787234</guid>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 12:54:14 GMT</pubDate>
            <atom:updated>2026-10-29T12:54:14.603Z</atom:updated>
            <content:encoded><![CDATA[<p><em>I started this blog post almost 10 months ago and never finished. Then I just recently heard of a few companies that have started to actually do almost exactly this so I decided to finish it up.</em></p><p>For years, it was always the same routine. Study and memorize Leetcode problems for an interview, get the job and rarely ever reuse any of the algorithms that you lost countless hours of sleep and stress on.</p><p>In the past 18 months, the entire AI landscape has changed the way we work and we need to change the way we interview. You still need to know architecture, you still need to know patterns but Leetcode and way we performed interviews is gone. Many large companies are openly admitting that they are no longer even using IDEs for most tasks and instead have moved to Agentic flows with upwards of 50+ agents running tasks in parallel. There are numerous articles like <a href="https://dev.to/dosanko_tousan/code-review-is-dead-and-in-5-years-senior-engineers-will-be-too-the-pipeline-collapse-and-how-447b">Code Review is Dead</a> or <a href="https://franciscomt.medium.com/will-humans-still-review-code-a6f7d3f0c39c">Will Humans still review code?</a> talking about no longer even reviewing code and instead dependent on AI to assist with the generation and testing/review of the code.</p><p>With the rapid move towards this type of work, why would we continue to interview with leetcode? That’s the wrong type of test for the new era that we are in. The best engineers are no longer the ones who spent countless hours memorizing often unrealistic coding problems or seeing how fast they could write a sample application, it’s now moving to how they can best utilize the tools.</p><h3>Prompt Interviews</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RaXICazPfstsZgnStP9WHw.png" /></figure><p>Thinking about the future of interviews using these tools, It’s a new set of skills and interview process with actual real world problems and designs.</p><p>The candidate gets a login link to a website that has several different AI tools like Codex, Claude Code, Cursor, Antigravity, etc. available in the browser and the user picks the tool that they want to use. They select the AI tool of choice and are prompted with a real world problem or task that must be completed within a certain period. Probably 60–90 minutes max, with the entire process recorded. Screen, prompts, tool-calls, outputs, and all.</p><p>Instead of a “Clone Graph” question, it may be debugging a broken service. The great part of this is it becomes easy to develop interview scenarios custom to their actual business.</p><blockquote>“You’ve inherited a Node.js REST API that’s intermittently returning 500 errors in production. Here’s the repo and the last 1000 lines of logs. Diagnose the issue and fix it.”</blockquote><p>During this time, the system is capturing metrics on the entire session.</p><ul><li>How many tokens did they use?</li><li>What Model(s) did they use?</li><li>How many prompts did it take and how detailed was each prompt?</li><li>Did they plan or just jump straight to prompting?</li><li>Did they spend time setting up Skills, Agents, Sub-Agents, etc?</li><li>How many agents/sub-agents were used?</li><li>Did the code compile and run? Was proper test coverage added?</li><li>Did they make good architecture decisions?</li><li>How did they review the agents work?</li></ul><p>This process would actually look much closer to what an engineer would actually be doing once they get hired as opposed to memorizing an algorithm that they will likely never use again.</p><h3>What This Means for Hiring Managers</h3><p>The interview process doesn’t just need to change for candidates, it needs to change for the people running them too. Start asking whether they read the existing code before changing it, whether they caught the bug the AI introduced, and whether they made good decisions about when to stop or reset context because it was going off track. That’s what matters now.</p><p>Give candidates a real environment. A blank editor with a contrived problem isn’t where your engineers work. Hand them a repo with history, a broken test, and a README with gaps. Testing how they handle ambiguity is much closer to a real work.</p><p>Record the entire session, not just the output. Two candidates can produce the exact same code through but use completely different processes. One of them may scale and the other may not. The prompts, the wrong turns, restarting from scratch, and numerous other signals indicate how they will work in your company.</p><p>Your interviewers also need to have used these tools before evaluating others on them. If your hiring panel has never worked in an agentic workflow, they won’t know what good looks like. That’s a problem you need to fix before the first interview.</p><p>The engineers who thrive in this new environment aren’t the ones who know the most. They’re the ones who know what to ask, when to trust the output, and when to push back on it. Understand the architectures and patterns rather then some random leetcode group of questions. That’s what you should be hiring for.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69d5de787234" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Support” for Open Source Software]]></title>
            <link>https://medium.com/@slimm609/support-for-open-source-software-18526464f265?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/18526464f265</guid>
            <category><![CDATA[compliance]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Fri, 05 Jan 2024 13:17:00 GMT</pubDate>
            <atom:updated>2026-02-04T16:44:59.818Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZuAMTkOxQ3v8nse3OG3hQ.jpeg" /><figcaption>Photo from Ilya Pavlov on Unsplash</figcaption></figure><p>“Support”, “End of Support”, and “End of Life” notices are an interesting topic when dealing with Open Source software. If we look at some of the industry controls like DISA STIGs Control ID <a href="https://www.stigviewer.com/stig/application_security_and_development/2018-12-24/finding/V-70395">V-70395</a>, it states <em>“All products must be supported by the vendor or the development team.” </em>Which simply means that you must be running supported software. Similarly if we look at PCI DSS 6.2, it states <em>“Ensure that all system components and software are protected from known vulnerabilities by installing the applicable security patches provided by the manufacturer.” </em>which is somewhat similar to the DISA STIG Control. These controls are intended to ensure that software is supported and up-to-date from known vulnerabilities and when using Commercial off-the-shelf (<a href="https://en.wikipedia.org/wiki/Commercial_off-the-shelf">COTS</a>) and Open Source Software. But what does “supported” really mean with open source software?</p><h4>Commercial Software</h4><p>As most people are aware, maintaining the security of your applications is extremely important. One key aspect in this regard is the continuous updating of software to ensure that you are operating a recent version that hopefully minimizes vulnerabilities. Ideally, those keeping applications updated should result in a state where your software is free from known vulnerabilities, or at the very least, free from publicly disclosed vulnerabilities while working on getting it patched.</p><p>The significance of this process lies in the fact that many providers of commercial software maintain internal mechanisms for tracking and addressing software defects. These often include private bug trackers, restricted bug bounty programs, and highly guarded access to source code. While these measures may enhance some security controls by preventing widespread knowledge of software vulnerabilities, they also place the onus on users to actively seek out and implement updates.</p><p>The discovery and release of new vulnerabilities is happening much more often year after year. In such cases, your primary recourse becomes updating the software to a version that has been patched against these vulnerabilities. This process entails installing a new version of the software which should have undergone testing, bug fixing, and security enhancements.</p><p>With COTS software, you typically have a legal agreement with the vendor to get support from them. This is usually in the details of the purchase of the software license. For the duration of the license terms, the vendors usually have an legal obligation to provide support and patches to the software, but it’s your job to keep the version you are running updated to the latest release.</p><h4>Open Source Software</h4><p>However, with Open Source software, there often isn’t a software license or contract for support. Open Source software typically has a license but not in the same term as vendor software licenses or vendor agreement. These Open Source licenses includes licenses like <a href="https://www.gnu.org/licenses/gpl-3.0.en.html">GPL</a>, <a href="https://www.mozilla.org/en-US/MPL/">MPL</a>, <a href="https://opensource.org/license/mit/">MIT License</a>, <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache License</a>, and others.</p><p>Open Source licenses typically all revolve around providing software out to the public with very little conditions. Some of them have more details then others but the ideas behind them are mostly similar, which is the sharing of the software publicly free of charge. However, “free of charge” is not the only thing in the license. If we look specifically at the <a href="https://opensource.org/license/mit/">MIT License</a>.</p><blockquote>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</blockquote><p>Based on the MIT license, any Open Source Software used with this license is provided “AS-IS” and “WITHOUT WARRANTY OF ANY KIND”. This also means there is no condition of “Support” provided. This has been a common misunderstanding in the industry and several articles or blog posts have been written discussing this in much more detail.</p><p><a href="https://mikemcquaid.com/open-source-maintainers-owe-you-nothing/">Open Source Maintainers Owe You Nothing</a> from 2018 expresses that “The way the software is today is all that the maintainers ever agree to provide you (bugs and all)”. Jacob Tomlinson also wrote about this in his page <a href="https://jacobtomlinson.dev/posts/2022/dont-be-that-open-source-user-dont-be-me/">Don’t be that open-source user, don’t be me</a> where he talks about his experiences with Open Source software and “Support”. Patrick from raccoon.onyxbits.de wrote an article <a href="https://raccoon.onyxbits.de/blog/bugreport-free-support/">No, “Open Source” does not mean “Includes Free Support”</a> and the follow-up to the first article <a href="https://raccoon.onyxbits.de/blog/reactions-bugreport-free-support/">The aftermath of “No, ‘Open Source’ does not mean ‘Includes Free Support’”</a>.</p><p>All of these articles go back to an important part to understand about Open Source Software. There is no support and no requirement that any bug or even vulnerability is ever fixed, and the software you are running is “AS-IS”. CVE-2021–44228 (Log4Shell) was a 10/10 CVSS severity and while the community fixed the issue pretty quick, there was no requirement for anyone to actually fix the issue. Log4Shell was so bad that several CDN’s even implemented code to help block the issue before the fix was even released. However if it wasn’t fixed, there was no vendor or company that you could contact and force them to fix. This is the case for every single bug or vulnerability found in any Open Source project. Including the Linux kernel, OpenSSL, Kubernetes, Docker, openJDK, or any other project. While it wasn’t a CVE, I personally opened issue with Open Source Docker back in <strong>early</strong> <strong>2017</strong> and the issue is still open and has no resolution. I found workarounds for the issue but the core issue still exists over 6 years later even in the latest Docker release but unless I wanted to spend the time to personally debug and fix the issue myself, there is no guarentee that it will ever be fixed and there is no support team I can pressure to fix it.</p><p>How likely is this to happen in the larger and very active projects? Not very likely. Is it something you need to be aware of and account the possibility of it happening as part of your overall security plan? Absolutely! When taking a dependency on any Open Source application, you should review the popularity and maturity of the project, the number of developers supporting the project, and also your ability to manage or contribute to the project if something were to happen and there was a critical issue that needed resolved immediately.</p><h4>End-of-Life/End-of-Support</h4><p>When software goes End-of-Life or End-of-Support, this marks the point at which the software’s official support and updates are no longer provided by the original developers. End-of-life software is a reality that organizations must deal with, and it presents its own unique challenges. As software continues to advance, older versions eventually become outdated, lacking compatibility with modern systems, and potentially vulnerable to security risks.</p><p>While the End-of-Life phase may mark the end of official “support”, it does not signify the end of the requirement to maintain the security and functionality of the systems. Sometimes that software is more difficult to update or get to a new version for whatever reason. This is where back-porting patches and self-maintenance comes into play.</p><p>As mentioned above, with most open source software there is no official support so it becomes your teams requirement to maintain this if it is required for a longer period. Backporting of patches isn’t a new concept and is done by many companies and teams. Red Hat Enterprise Linux and Amazon Linux are 2 of the most popular distros that backport patches. Crowdstrike has a good article about <a href="https://www.crowdstrike.com/cybersecurity-101/backporting/">backporting of patches</a>.</p><h4>Best Practices for Open Source Software</h4><p>There are several things that can be done to help reduce the risk of this and help ensure you are selecting the best project for your needs and reducing the risk of vulnerabilities</p><ul><li>Review the number of stars and forks</li><li>Review the number commits and contributors</li><li>Review Commits, Issues, and Pull Requests to see activity</li><li>Compare against similar projects to ensure you are picking the most ideal project</li><li>Develop a selection and approval process for using new open source projects</li><li>Have teams prepared to be able to contribute fixes if or when needed</li></ul><h4>Conclusion</h4><p>Most teams and companies heavily rely on Open Source Software but many do not account for potentially having to deal with bugs or open source issues. Bugs or CVEs may be found and not resolved in the manner or timeframe needed. Using Open Source Software may require patching, or maintaining the code within your own team and being able to recompile the software yourself. While it may not happen, this is something you need to think about and plan for as part of your security and contingency plans.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18526464f265" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programming Language Performance Comparisons]]></title>
            <link>https://medium.com/@slimm609/programming-language-performance-comparisons-9a55abad28f4?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a55abad28f4</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[performance-testing]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 12:51:12 GMT</pubDate>
            <atom:updated>2023-07-27T12:51:12.337Z</atom:updated>
            <content:encoded><![CDATA[<p>Not long ago I was reading a <a href="https://medium.com/deno-the-complete-reference/go-vs-rust-hello-world-http-server-performance-comparison-f8f67e308db">Medium article</a> about a performance comparison between Go and Rust programming languages and a few things caught my eye and why simple benchmarks don’t always tell the full story. Benchmarks between different languages should always be taken with a grain of salt as there are many variables that come into play. There are different libraries, configurations, etc for each language that needs to be accounted for and taken into consideration. This article is <strong>not</strong> intended to be a performance comparison between Rust and Go but rather to show how different changes can greatly affect the results.</p><p><em>Note: I do not personally know the author of the linked article and this is not intended to make any statements about the article.</em></p><p>We will start with the code from the article linked above. For go the version is 1.20.5 and rust is 1.70.0. All tests are run with 500 concurrent connections for 5 million total requests.</p><h4>Benchmarking</h4><p>For the benchmarks, we will leverage the same tool as well. <a href="https://github.com/codesenberg/bombardier">bombardier</a> is the tool used to perform the load testing. The testing is performed over the network using 2 linux machines. bombardier virtual machine is a 12 core Xeon 6330/2.0 Ghz w/ 48GB Ram and the applications are on a virtual machine with 36 core Xeon 6330/2.0 Ghz w/ 128GB Ram. This will not include things like cpu or memory usage of any of the applications.</p><h3>Original code</h3><p>Lets start off by using the same code (minus the switch to listen on 0.0.0.0 instead of 127.0.0.1)</p><h4>Go</h4><pre>package main<br><br>import (<br>  &quot;io&quot;<br>  &quot;net/http&quot;<br>)<br><br>func main() {<br>  http.HandleFunc(&quot;/&quot;, helloWorld)<br>  http.ListenAndServe(&quot;0.0.0.0:3000&quot;, nil)<br>}<br><br>func helloWorld(w http.ResponseWriter, r *http.Request) {<br>  io.WriteString(w, &quot;Hello world!&quot;)<br>}</pre><h4>Rust</h4><pre>use std::convert::Infallible;<br>use std::net::SocketAddr;<br><br>use bytes::Bytes;<br>use http_body_util::Full;<br>use hyper::server::conn::http1;<br>use hyper::service::service_fn;<br>use hyper::{Request, Response};<br>use tokio::net::TcpListener;<br><br>async fn hello(_: Request&lt;hyper::body::Incoming&gt;) -&gt; Result&lt;Response&lt;Full&lt;Bytes&gt;&gt;, Infallible&gt; {<br>  let response = Response::builder()<br>    .header(&quot;Content-type&quot;, &quot;text/plain&quot;)<br>    .body(Full::new(Bytes::from(&quot;Hello World!&quot;)))<br>    .unwrap();<br>  Ok(response)<br>}<br><br>#[tokio::main]<br>pub async fn main() -&gt; Result&lt;(), Box&lt;dyn std::error::Error + Send + Sync&gt;&gt; {<br>  let addr: SocketAddr = ([0, 0, 0, 0], 3000).into();<br>  let listener = TcpListener::bind(addr).await?;<br>  loop {<br>    let (stream, _) = listener.accept().await?;<br>    tokio::task::spawn(async move {<br>      if let Err(err) = http1::Builder::new()<br>        .serve_connection(stream, service_fn(hello)).await {<br>          println!(&quot;Error serving connection: {:?}&quot;, err);<br>        }<br>    });<br>  }<br>}</pre><h4>Results</h4><p>Go</p><pre>5000000 request(s) using 500 connection(s)<br><br>Statistics        Avg      Stdev        Max<br>  Reqs/sec    159075.90   11830.95  179177.03<br>  Latency        1.25ms   328.14us    27.98ms<br>  HTTP codes:<br>    1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0<br>    others - 0<br>  Throughput:    32.31MB/s</pre><p>Rust</p><pre>5000000 request(s) using 500 connection(s)<br><br>Statistics        Avg      Stdev        Max<br>  Reqs/sec    172748.06   11164.04  195682.76<br>  Latency        2.89ms     1.24ms   181.05ms<br>  HTTP codes:<br>    1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0<br>    others - 0<br>  Throughput:    35.06MB/s</pre><p>Based on these results we can see that Go had an average of 159k req/sec while Rust had an average of 172.7k req/sec. This means that Rust was able to achieve 13.6k req/sec and 2.75MB/s faster results. At first glance, this makes rust seem faster than Go, but let’s look at the 2 example blocks above. The Go example is using net/http which is built into go by default while Rust is using hyper which describes itself as a “Fast and safe HTTP for the Rust language.” So this is comparing the default net/http in Golang to an external library of hyper in Rust.</p><p>Let’s run some different cases to see how that affects the requests and throughput.</p><h4>Default Rust TcpListener</h4><p>Let’s look at a example default webserver in Rust and see how that performs. Rosetta Code has a <a href="https://rosettacode.org/wiki/Hello_world/Web_server#Rust">hello world example</a> that we can look at. The only updates made are to listen over the network on port 3000 and to not log every call since we are doing 5 million calls.</p><pre>use std::net::{Shutdown, TcpListener};<br>use std::thread;<br>use std::io::Write;<br><br>const RESPONSE: &amp;&#39;static [u8] = b&quot;HTTP/1.1 200 OK\r<br>Content-Type: text/html; charset=UTF-8\r\n\r<br>&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Bye-bye baby bye-bye&lt;/title&gt;<br>&lt;style&gt;body { background-color: #111 }<br>h1 { font-size:4cm; text-align: center; color: black;<br>text-shadow: 0 0 2mm red}&lt;/style&gt;&lt;/head&gt;<br>&lt;body&gt;&lt;h1&gt;Goodbye, world!&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;\r&quot;;<br><br><br>fn main() {<br>    let listener = TcpListener::bind(&quot;0.0.0.0:3000&quot;).unwrap();<br><br>    for stream in listener.incoming() {<br>        thread::spawn(move || {<br>            let mut stream = stream.unwrap();<br>            let _ = stream.write(RESPONSE);<br>            stream.shutdown(Shutdown::Write).unwrap();<br>        });<br>    }<br>}</pre><p>Running the same tests, we can see the results below are now only reaching 16k req/sec. That means this one is 156k req/sec <em>slower</em> than the previous Rust example and now the Go example using net/http is 142k req/sec <em>faster</em> than Rust.</p><pre>5000000 request(s) using 500 connection(s)<br><br>Statistics        Avg      Stdev        Max<br>  Reqs/sec     16295.75    3545.23   30155.79<br>  Latency       30.76ms   133.76ms      7.31s<br>  HTTP codes:<br>    1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0<br>    others - 0<br>  Throughput:     5.52MB/s</pre><h4>Go w/ Fasthttp</h4><p><a href="https://github.com/valyala/fasthttp">Fasthttp</a> is a “Fast HTTP package for Go” that is tuned for high performance and claims to be up to 10x faster than the standard net/http that is built into Go. This would be a comparable library to the Rust hyper library. If we reference the example that is in the fasthttp README, we can generate an example to use for testing.</p><pre>package main<br><br>import (<br> &quot;io&quot;<br> &quot;github.com/valyala/fasthttp&quot;<br>)<br><br>func fastHTTPHandler(ctx *fasthttp.RequestCtx) {<br> io.WriteString(ctx, &quot;Hello world!&quot;)<br>}<br><br>func main() {<br>  fasthttp.ListenAndServe(&quot;0.0.0.0:3000&quot;, fastHTTPHandler)<br>}</pre><p>When we run the tests again, you can now see that fasthttp was able to achieve 215k req/sec. This results in a 56k req/sec improvement over net/http and would now mean that Go is faster than Rust.</p><pre>5000000 request(s) using 500 connection(s)<br><br>Statistics        Avg      Stdev        Max<br>  Reqs/sec    215686.76   50039.14  303304.69<br>  Latency        2.31ms   821.50us    54.10ms<br>  HTTP codes:<br>    1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0<br>    others - 0<br>  Throughput:    43.77MB/s</pre><h4>Golang fasthttp with SO_REUSEPORT</h4><p>Linux supports <a href="https://lwn.net/Articles/542629/">SO_REUSEPORT</a> which allows multiple processes to share a single port binding to achieve higher performance. By leveraging the <a href="https://pkg.go.dev/github.com/valyala/fasthttp/reuseport">so_reuseport</a> support in fasthttp, we can run the test again to try to achieve even higher performance.</p><pre>package main<br><br>import (<br> &quot;io&quot;<br> &quot;log&quot;<br><br> &quot;github.com/valyala/fasthttp&quot;<br> &quot;github.com/valyala/fasthttp/reuseport&quot;<br>)<br><br>func main() {<br> ln, err := reuseport.Listen(&quot;tcp4&quot;, &quot;0.0.0.0:3000&quot;)<br> if err != nil {<br>  log.Fatalf(&quot;error in reuseport listener: %v&quot;, err)<br> }<br><br> if err = fasthttp.Serve(ln, requestHandler); err != nil {<br>  log.Fatalf(&quot;error in fasthttp Server: %v&quot;, err)<br> }<br>}<br><br>func requestHandler(ctx *fasthttp.RequestCtx) {<br> io.WriteString(ctx, &quot;Hello world!&quot;)<br>}</pre><p>With this performance test we now achieved 227k req/sec which is a 12k req/sec improvement over even the regular fasthttp configuration, a 55k req/sec over Rust and a 68k req/sec over the default Gonet/http.</p><pre>5000000 request(s) using 500 connection(s)<br><br>Statistics        Avg      Stdev        Max<br>  Reqs/sec    227762.52   20861.44  281661.93<br>  Latency        2.19ms   316.39us    36.66ms<br>  HTTP codes:<br>    1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0<br>    others - 0<br>  Throughput:    46.30MB/s</pre><h3>Conclusion</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a6a33e49966218324e3f419ea186639/href">https://medium.com/media/3a6a33e49966218324e3f419ea186639/href</a></iframe><p>With these results, we can see that Go is the faster than Rust in this case but that’s not really the important part. What we should pay attention to is Go is faster than Go, Rust is faster than Rust, Rust is faster than Go, and Go is faster than Rust. Pick any one and it is faster than another one from the other language or even the same language. I am sure there are additional optimizations that can be done to both languages to make it faster but the important part isn’t really the language but how you configure it and the libraries used. Both languages are VERY fast and can easily support most use cases.</p><p>If you are already using 1 language, it rarely makes sense to completely switch to a different language unless there is a very specific use case, Instead spend the time optimizing and improving on the language you are already using.</p><p>The <strong><em>best</em></strong> programming language is the one you and/or your team can effectively maintain. At a previous company, anytime someone wanted to use a new language, we had a rule that at least 50% of the team needed to agree to learning/supporting the applications written in that language and it helped ensure that the team focused on using and improving the languages already in use.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a55abad28f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosted Gitlab License Validation Vulnerability]]></title>
            <link>https://medium.com/@slimm609/hosted-gitlab-license-validation-vulnerability-720409212901?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/720409212901</guid>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Thu, 22 Dec 2022 14:01:10 GMT</pubDate>
            <atom:updated>2022-12-22T15:28:37.767Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>DISCLAIMER: This information is only for educational purposes. This is no longer covered under the scope of the bug bounty program however, at the time when I originally reported, it was covered under the </em></strong><a href="https://hackerone.com/gitlab/policy_versions?change=3671770&amp;type=team"><strong><em>policy</em></strong></a><strong><em>. The licenses were removed from the scope of the bug bounty program on May 19th, 2022. Modifying or tampering with the licenses is against the terms of service and should not be done for any purposes other than education. I also notified Gitlab before posting this.</em></strong></p><p>In 2020, I started doing some security testing on Self-hosted Gitlab Enterprise. While looking at it I discovered an issue with how the license validation works on all versions of self-hosted Gitlab. I reported this issue to Gitlab on HackerOne back in April 2020 and they stated it was a known issue and they had an open issue filed for it. Since then they have started to move to a subscription model but legacy licensing is still supported so the software is still affected by this issue.</p><p>Gitlab provides a <a href="https://about.gitlab.com/free-trial/?hosted=self-managed">30-day trial license</a> that can be requested via email. By using this trial license, it can be turned into a permanent license for any number of features, any number of users, and for any expiration date desired.</p><p>Gitlab self-hosted license validation happens by the Gitlab team generating a license that is encrypted with AES-128-CBC and contains all the account data for the Gitlab license including the account ID, user count, and much more. The license itself is loaded into the application and verified using a public key that ships with all versions of Gitlab. The public key is located at /opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub</p><p>By simply generating a new license file and public/private keys, anyone can replace the license in self-hosted Gitlab and the application will validate the license as proper.</p><h3>Generating a new public/private key pair</h3><p>In the code, there is no type of validation of the public key that is used for the license key so a new public/private key can just be created to replace the existing public key and we will use the private key to encrypt the trial license after modifying the text. Something as simple as 2 quick OpenSSL commands, we can generate a new public/private key pair that we can use instead of Gitlab’s shipped keys.</p><pre>openssl genrsa -out private.pem 2048<br>openssl rsa -in private.pem -outform PEM -pubout -out public.pem</pre><h3>Decrypting the Trial license</h3><p>Over time the license format and fields have changed some but anytime a trial license is generated, the current format of the license is provided. Using the public key included with the Gitlab self-hosted installer or docker image, the public key can be decrypted. We can use RSA to decrypt using the .license_encryption_key.pub file to decrypt the contents of the trial license. The license is base64 encoded JSON.</p><pre>{<br>  &quot;data&quot;:&quot;Wkiyalmj6GAosD+4uDfBHkZGHjKbuSIkj8/EfQkFWPIoBhov9p+zRGiPseKCGZi09VecSitmkdTPq6EgPpD3dAXXnwunkqtu+J+Ssx4XVNepqUzgJnv+qiagiWK7C5VKJGFoldGzu0HT7NL3NtFOv0CU5NqHEDPy6SVxznRt7lGhC7YT4jWa6hvsSkomAHlcsWBKofJ594xdbnGGq0VD95CkdH2A6NK8Rb0wGMq3LS9FCeAV5zPR+gD0e2xWt32IkfSobxni7iK2kf52lMnLUNmZPfDUYvKb5kB2heJ8a7vvPuXPVl7HmYSpfASr9I8GfwfX87tSYaN7HmOK0QkFTN7qmr5yG/W0WqIxnmKZ7Y7J5kuCIe/vwYIFuLSqse5qC+Rf1W1CL5IZ9St7QM4msThD0eAj8B3SaYbj48ook/MGkEDn9+mV6Xy4IJz5mM0UfDlM+j5wHQIUgBGxCUEj2aQ260NeFYFw2BhnpEdf4hgK8TcxiQSaaUP4Gd0SUeX7iMXir6oPVhg9FTNJufHUn8eAYrmlCXRN36AYzaUB6cteyS/p9IEhG9Ad5Cbou2jFyoGMFdIs8c61yvC1mCcGbCntqRIpmBq0nMzHY9IR6z5u0fbCLlcWGVp7+3ST8OM8rbvYSNHK/Gb6QprMLUvwSl9VGDfmPLyMLPzgvMXH91YfM2Gt9i0WVQieLgIff1wnboqb3+E8R093jqpbdAjQwh4OwuHC76ZENpLueIe4FX1P2Bj6ArLRdn4WBXn3r0a+AENZ/ZBHch17MDQ4TQResbK+DNXyKHvupld0cK9JzZMbyEZMEAx3zDhxUBv3Q0g7eO70qn4J1tHNvk+Qx6RI+9Fvgr3tZlt8vizQupDg06XSLFo/Vu5z4KNFMc1EtPGq&quot;,<br>  &quot;key&quot;:&quot;dQPK4ymuQxUmfGS+9iCOqsbyYywNqqd6C2BcImVunu4V2sQa3qUyHAYPeDEd9MjVUk+9PWbfehFlwHTfsoqz7FGQSpx0+rQiCE29+XMLNyxuJXGZ4H2i+xx6vKIFV7de80nuB+7L450AlSBVFgfD7dKnthh+xObmTDCGEJvRZsMX6RqjIr30hKQpagePZykE7hJHxd67LjHjHi29uRR1HEGeFNKetjRvQicK5i9q8IaNPzOuWM4NpYYC8h43148XvnvjXnZxXZmKUgD1K+3sookHOmeKm2cjbyzYtXb5A5mNDEs4S4ooqJA6q+8OSg1V5wQRz+qiVV9w3VAHbK5tvw==&quot;,<br>  &quot;iv&quot;:&quot;FcaEgrLTbqT6WsIIglpU0g==&quot;<br>}</pre><p>The 3 parts of the key are the data, keyand iv. The data contains all the license details, key and iv are used to decrypt the data using AES-128-CBC. However, the key is first encrypted using the GitLab private key and decrypted using the shipped public key.</p><p>Below are the contents of a trial license file after decryption</p><pre>{<br>  &quot;version&quot;: 1,<br>  &quot;licensee&quot;: {<br>    &quot;Name&quot;: &quot;john doe&quot;,<br>    &quot;Email&quot;: &quot;john.doe@johndoe.com&quot;,<br>    &quot;Company&quot;: &quot;Johndoe Inc.&quot;<br>  },<br>  &quot;issued_at&quot;: &quot;2022-12-02&quot;,<br>  &quot;expires_at&quot;: &quot;2023-01-01&quot;,<br>  &quot;notify_admins_at&quot;: &quot;2022-12-23&quot;,<br>  &quot;notify_users_at&quot;: &quot;2022-12-23&quot;,<br>  &quot;cloud_licensing_enabled&quot;: false,<br>  &quot;offline_cloud_licensing_enabled&quot;: false,<br>  &quot;auto_renew_enabled&quot;: false,<br>  &quot;seat_reconciliation_enabled&quot;: false,<br>  &quot;operational_metrics_enabled&quot;: false,<br>  &quot;generated_from_customers_dot&quot;: true,<br>  &quot;restrictions&quot;: {<br>    &quot;id&quot;: 8675309,<br>    &quot;previous_user_count&quot;: null,<br>    &quot;trueup_quantity&quot;: null,<br>    &quot;trueup_from&quot;: null,<br>    &quot;trueup_to&quot;: null,<br>    &quot;active_user_count&quot;: 100,<br>    &quot;subscription_id&quot;: null,<br>    &quot;subscription_name&quot;: null,<br>    &quot;plan&quot;: &quot;ultimate&quot;,<br>    &quot;trial&quot;: true,<br>    &quot;reconciliation_completed&quot;: false<br>  }<br>}</pre><h3>Encrypting the Trial license</h3><p>Because the is no validation on the public key that is used to validate the license, we can just reverse the decryption process to encrypt the data back to the format needed for Gitlab and replace the existing public key with our own key and restart the server. Once we have the format of the trial license, we can modify any of the fields we want to update to the new values such as expiration date, number of users, or any other data we want like changing trial from false to true, modify the expiration date, change the num</p><pre>{<br>  &quot;version&quot;: 1,<br>  &quot;licensee&quot;: {<br>    &quot;Name&quot;: &quot;john doe&quot;,<br>    &quot;Email&quot;: &quot;john.doe@johndoe.com&quot;,<br>    &quot;Company&quot;: &quot;Johndoe Inc.&quot;<br>  },<br>  &quot;issued_at&quot;: &quot;2022-12-02&quot;,<br>  &quot;expires_at&quot;: &quot;2099-01-01&quot;,<br>  &quot;notify_admins_at&quot;: &quot;2098-12-23&quot;,<br>  &quot;notify_users_at&quot;: &quot;2098-12-23&quot;,<br>  &quot;cloud_licensing_enabled&quot;: false,<br>  &quot;offline_cloud_licensing_enabled&quot;: false,<br>  &quot;auto_renew_enabled&quot;: false,<br>  &quot;seat_reconciliation_enabled&quot;: false,<br>  &quot;operational_metrics_enabled&quot;: false,<br>  &quot;generated_from_customers_dot&quot;: true,<br>  &quot;restrictions&quot;: {<br>    &quot;id&quot;: 0000001,<br>    &quot;previous_user_count&quot;: null,<br>    &quot;trueup_quantity&quot;: null,<br>    &quot;trueup_from&quot;: null,<br>    &quot;trueup_to&quot;: null,<br>    &quot;active_user_count&quot;: 1000000,<br>    &quot;subscription_id&quot;: null,<br>    &quot;subscription_name&quot;: null,<br>    &quot;plan&quot;: &quot;ultimate&quot;,<br>    &quot;trial&quot;: false,<br>    &quot;reconciliation_completed&quot;: true<br>  }<br>}</pre><p>With this updated code, we can simply reverse the decryption process. We can generate a random key and iv, encrypt the JSON with the new key and iv, then finally encrypt the random key with the RSA private key. Then base64 encode the 3 sections (data,key,iv) then build a new JSON block like the original format and finally, base64 encode it. Once completed, we should have a validate key that GitLab understands but just wouldn’t verify since it was signed by a different key.</p><p>However, as mentioned above, there is no validation on the public key, we can just replace the public key with our own generated key and restart the Gitlab process. All that is needed is to upload the license via the web UI and it validates the license just fine. As you can see in the image below, The license is valid for 79 years (until 2099) for 1 million users with the Ultimate plan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQvLU5r8Xq7w8bAZCE_wBQ.png" /><figcaption>Validated license</figcaption></figure><h3>License Security</h3><p>Offline license validation is a difficult thing to protect. Anytime the software is running on a local machine, it becomes much more difficult to protect. In the case of Gitlab, since it is written in ruby and all the source code is shipped to the user, it becomes even more difficult. Gitlab has started to move to a subscription model which connects out to the internet and avoids this issue entirely. Though with some customers using Gitlab in a completely isolated environment, it will be difficult to soley rely on the that solution.</p><p>When it comes to providing any type of “self-hosted” software, licenses can only go so far and will always be a best-effort approach. We have seen this over the years with all types of software license generators for Windows, Adobe, and countless other applications. When someone has access to debug and read the calls to the hardware, they will always have the advantage.</p><p>There are several things that can be done to help with these types of issues on Gitlab and other software as well. There are countless numbers of them but I will try and include a few here.</p><ul><li>Using different licenses/elements for trial licenses vs regular licenses</li><li>Don’t offer fully disconnected trials, this allows systems like subscription keys to be leveraged which “check-in”.</li><li>Compiled applications will always be more difficult to reverse than readable source code.</li><li>Leveraging some data from the system after install which must be done via an “exchange” process.</li></ul><h3>Summary</h3><p>Software licensing for “self-hosted” software will always be a difficult thing for vendors and this is a place where obfuscation can be leveraged to increase the difficulty required to reverse or subvert the licensing models. Gitlab had some issues with the way it was validating licenses but they are working on improving it. I haven’t had a chance to dig through the subscription model but not sure I will since it’s no longer covered under the bounty program which is a shame because while it’s not a direct security vulnerability, it’s still interesting code where finding and reporting issues still benefits the product.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=720409212901" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why you should be using Secretive for SSH keys]]></title>
            <link>https://medium.com/@slimm609/why-you-should-be-using-secretive-for-ssh-keys-c770d16bfc7d?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/c770d16bfc7d</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[ssh-keys]]></category>
            <category><![CDATA[secure-coding]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Mon, 05 Sep 2022 21:27:33 GMT</pubDate>
            <atom:updated>2022-09-05T21:27:33.254Z</atom:updated>
            <content:encoded><![CDATA[<p>If you use a Mac, you should be using <a href="https://github.com/maxgoedjen/secretive">Secretive</a> for managing your SSH keys. Secretive uses the Mac <a href="https://support.apple.com/guide/security/secure-enclave-sec59b0b31ff/web">Secure Enclave</a> to generate and store SSH keys that can not be exported or removed from the system. Secretive provides an interface to communicate with Mac’s Secure Enclave for SSH key actions.</p><h3>What is Secure Enclave?</h3><p>Secure Enclave is described as “a dedicated secure subsystem integrated into Apple systems on chip (SoCs)&quot;, an independent processer designed to protect keys and sensitive items inside a logically isolated section of the processor.</p><p>It works by storing private keys inside a hardware-based key manager and applications that need to encrypt and decrypt data just interact with the Secure Enclave. The private keys inside the Secure Enclave are never backed up or exported outside the chip. This makes it very difficult for an attacker to get the private key. The Secure Enclave contains other functions as well such as a random number generator, An AES engine, and Public Key Accelerator</p><figure><img alt="https://support.apple.com/guide/security/secure-enclave-sec59b0b31ff/web" src="https://cdn-images-1.medium.com/max/1024/0*qtycKL1tmsWJyhy-.png" /><figcaption>Secure Enclave Design from Apple.</figcaption></figure><p>Secure Enclave provides an API for services to interact with the SoC. This means that the encryption/decryption happens in the chip itself and not in the normal operating system.</p><h3>Secretive</h3><p>Secretive is an application that manages SSH keys created and stored inside the Mac Secure Enclave and provides an agent to communicate with the private key. This allows the SSH keys to be securely stored in a hardware-based module without the capability to export the private key. This means that it can not be copied to different machines and reused and each machine will require its own key to be generated on each specific machine.</p><p>Secretive can be installed via <a href="https://brew.sh/">homebrew</a> or via direct download from the GitHub project <a href="https://github.com/maxgoedjen/secretive/releases">releases</a> page.</p><pre>$ brew install secretive</pre><p>Once installed, start the Secretive application (cmd+space to open spotlight). During initial setup, follow the instructions to enable the ssh-agent. The first page describes what the agent does. Click install to take you to the agent configuration page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*G-X3ntiMG8hVBQoY9CsZsA.png" /></figure><p>From here you try theAdd it For Me button but I have seen it work intermittently on different machines. If you click the text it will copy it automatically and then put it into the global SSH configuration file. You can use your favorite editor to add the lines to the file.</p><pre>$ cat ~/.ssh/config</pre><pre>Host *<br>  IdentityAgent /Users/briandavis/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh</pre><p><em>Note: if you do not have a </em><em>.ssh directory in your user&#39;s home directory, ssh will create and set up the proper permissions if you just ssh to an active server then abort the connection. (</em><a href="https://sdf.org/"><em>SDF</em></a><em> offers free Unix shell access so connecting attempting to connect is not against the terms of service). You will need to type </em><em>yes to accept the host key. When prompted for a password just hit “Ctrl+c” to abort and then the </em><em>.ssh directory will be created with the proper permissions</em></p><pre>$ ssh sdf.org<br>The authenticity of host &#39;sdf.org (205.166.94.16)&#39; can&#39;t be established.<br>ED25519 key fingerprint is SHA256:ZjwbO7AU8rHJExYrmZS2LqGZ7WfdoELfMrF54W92PYA.<br>This key is not known by any other names<br>Are you sure you want to continue connecting (yes/no/[fingerprint])? yes<br>Warning: Permanently added &#39;sdf.org&#39; (ED25519) to the list of known hosts.<br><a href="/service/mailto:briandavis@sdf.org">briandavis@sdf.org</a>&#39;s password:</pre><p>Once completed click I added it manually then just click Okay on the final page.</p><p>On the Secretive main screen, there may be a box that says Secret Agent Is Not Running like below. This can take a few minutes to go away after you added it to the ssh configuration. It’s safe to ignore if you just completed the setup but if it hasn’t disappeared after a few minutes, click it and go through the setup again to make sure it&#39;s properly configured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*hdriJes9_8fz_A1D2ocSSA.png" /></figure><p>Now we need to create keys. On the main screen click the + symbol in the upper right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ogZ5Vt3dkKhhijxGH-d1VQ.png" /></figure><p>In the pop-up, give the key a name and click Create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1mfGsBVz_UWOGpFKCNU_w.png" /></figure><p>Once created, we will now have the SSH key listed on the side with the public details of the SSH key. As you can see, we do not have any of the private key details like we would normally have in the private key since it is stored in the Secure Enclave.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H5ErUsY-i92oqTntiRorgg.png" /></figure><h3>Add the public key to GitHub</h3><p>In your GitHub settings (<a href="https://github.com/settings/keys">https://github.com/settings/keys</a>) we can add the new key twice. Once for Authentication Keyand once Signing Key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RNAreOlr1mHzDra9AI2yqA.png" /></figure><p>You will then see them listed in your ssh keys. At this point, you should be able to authenticate with GitHub using the ssh key stored in Secure Enclave.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YRSm_TTxIF2457PGTUBCnA.png" /></figure><p>If you try to do a git fetch to an existing repository, you should see a popup to authorize the SSH key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*IBi8F8Ni1dEDY3kHwucuuw.png" /><figcaption>Authorize ssh key access</figcaption></figure><p>Once access is granted, the git commands should complete successfully.</p><pre>$ git fetch</pre><pre>remote: Enumerating objects: 47, done.<br>remote: Counting objects: 100% (47/47), done.<br>remote: Compressing objects: 100% (20/20), done.<br>remote: Total 47 (delta 26), reused 43 (delta 26), pack-reused 0<br>Unpacking objects: 100% (47/47), 14.33 KiB | 396.00 KiB/s, done.<br>From github.com:slimm609/checksec.sh<br>   baebb9a..d5b6bc5  main       -&gt; origin/main</pre><h3>Signing commits with Secretive</h3><p>Git has supported using GPG keys to sign commits for years but fairly recently added the ability to sign commits using SSH keys with Git version 2.34.</p><p>In February of 2022, Gitea added <a href="https://blog.gitea.io/2022/02/gitea-1.16.0-and-1.16.1-released/#add-support-for-ssh-commit-signing-17743httpsgithubcomgo-giteagiteapull17743">support for SSH key signing</a> followed by <a href="https://github.blog/changelog/2022-08-23-ssh-commit-verification-now-supported/">Github</a> in late August 2022. Gitlab is in the process of<a href="https://gitlab.com/gitlab-org/gitlab/-/issues/343879"> adding support for ssh signing</a> and will hopefully be completed soon.</p><p>To enable commit signing with ssh you must set the gpg format to ssh and set enable signing of commits.</p><pre>$ git config gpg.format ssh<br>$ git config commit.gpgsign true</pre><p>Now that we have enabled signing, we have to tell it which key to use for signing. We have to get this from the Secretive window for the key we want to use. The value that will be used is Public Key Path.</p><pre>$ git config user.signingKey /Users/briandavis/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/PublicKeys/1c389ca3957a60a80498c9adc985e07e.pub</pre><p>Finally, we need to set the SSH_AUTH_SOCK for our shell. This needs set because Git does not use the value set in ~/.ssh/config so we need to add this to the shell RC file. Note: you can get the values from Secretive by selecting Help then Setup Secretive</p><pre>export SSH_AUTH_SOCK=/Users/briandavis/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh</pre><p>Once these are complete, you should be able to sign commits using SSH.</p><p>When a commit is pushed up to a <a href="https://github.com/slimm609/ssh-signing-demo/commit/b9ea1717a63623865b1a9454f94cfd5d9ca9ffff">GitHub repo</a>, you can validate that it is signed and properly verified. If you hover over the Verified section, it will show details and that it was signed with a SSH key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*LARJAq-tDFDa5i752ths1w.png" /></figure><p>By comparing the SSH Fingerprint with what is shown in Secretive we can see that they match.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vjZIj5spxJ0Qd28vE6OEEw.png" /></figure><p>So we know that Secretive was used for the signing of the commit and that it is working properly.</p><h3>Summary</h3><p>Secretive dramatically improves the security of SSH keys on Mac computers. If you are using SSH for server access or using Git, You should be signing commits for integrity. Secretive helps add an additional layer to that security making it much more difficult for attackers to get access to the private keys used to push and sign code. With verified commits, users can validate the integrity of each commit and release to ensure that they came from the original author.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c770d16bfc7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cost-based Password Hashing]]></title>
            <link>https://medium.com/@slimm609/cost-based-password-hashing-b383bbb355df?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/b383bbb355df</guid>
            <category><![CDATA[argon2]]></category>
            <category><![CDATA[passwords]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Sun, 21 Aug 2022 18:18:19 GMT</pubDate>
            <atom:updated>2022-08-21T18:18:19.304Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*BdiIRZ7W0nuQPIdTy1lDQw.jpeg" /><figcaption>Bank vault picture from <a href="https://unsplash.com/@jdent">Jason Dent</a> on Unsplash</figcaption></figure><p>After spending some time at the password village at DEFCON 30 and reading an article several weeks ago about a <a href="https://arstechnica.com/information-technology/2022/07/intel-and-amd-cpus-vulnerable-to-a-new-speculative-execution-attack/">new vulnerability</a> in both Intel and AMD processors that “can covertly leak password data and other sensitive material” one thing caught my eye…</p><blockquote>The exploit can extract kernel memory from AMD CPUs with a bandwidth of 3.9 kB per second. The researchers said that it’s capable of locating and leaking a Linux computer’s root password hash from physical memory in about 28 minutes when running the Intel CPUs and in about 6 minutes for AMD CPUs.</blockquote><p>Unfortunately, even in 2022, there are 2 things we still suck at.</p><ul><li>Creating secure passwords</li><li>Using secure password hashing algorithms</li></ul><p>We have been trying to convince people to create secure passwords for years and years but still, the most common passwords are qwerty, password, and 123456. I am not going to spend much time talking about creating strong passwords since we have been doing that for decades and is going to continue. That’s a topic for a whole other discussion. So I am just going to say that you should use strong passwords that are unique for each site and a trusted password manager and ALWAYS set up <a href="https://en.wikipedia.org/wiki/Multi-factor_authentication">Multi-factor Authentication</a> whenever possible.</p><p>Instead, let’s talk about the password hashing algorithms to securely protect passwords on systems.</p><h3>Cost-Based Passwords Hashes</h3><p>Almost all the recommended password hashing algorithms include some kind of difficulty factor or Cost to increase the number of resources needed to hash the password. This can be either by requiring additional memory, additional CPU, the number of parallel threads, or even the number of iterations (rounds).</p><p>If we leverage the tuning options of the hashing algorithms we can increase the difficulty of computing each hash. When storing a password we use a <a href="https://en.wikipedia.org/wiki/Key_derivation_function#Password_hashing">one-way function</a>. After the initial hash is created and stored, we validate the password by using the same process with the user-provided input and see if we get the same output. If we get the same values, we know we have a match.</p><p>When we create the hash, we take the difficulty settings (memory, CPU, iterations, etc), the <a href="https://en.wikipedia.org/wiki/Salt_(cryptography)">salt</a>, and the plaintext user input then we generate the hash and compare. If we take a look at the hash we can see the breakdown of this info.</p><pre>$2b$10$KRGxLBS0LxevKhKyLRW1M.w0cqB396CYug0ztDrYZB6govAc62ggK</pre><p>The $ is a delimiter to split apart the values.</p><ul><li>2bis the cipher type. In this case, 2 is the value for <a href="https://en.wikipedia.org/wiki/Bcrypt">bcrypt</a> and version is b</li><li>10 is the number of log rounds. (2¹⁰)</li><li>KRGxLBS0LxevKhKyLRW1M is the <a href="https://en.wikipedia.org/wiki/Salt_(cryptography)">salt</a>. (<em>1234567812345678</em>)</li><li>w0cqB396CYug0ztDrYZB6govAc62ggK is the hashed password. (<em>random_password</em>)</li></ul><p>To validate that a password is correct, we would take the user input (random_password). Then look up the value that we have stored and get the settings for that password (cipher, rounds, and salt). We would then re-compute the value from the user input and the stored settings to make sure we get the same value that we have a record for.</p><p>We can increase the rounds, cost, or difficulty (depending on the hashing algorithm) to make it require more resources and take more time to perform the hash. If we increase the difficulty, it makes it harder (computationally expensive) for both ourselves and for any potential attackers that get a copy of the hashed value. The difference is the number of times that a hash much be performed by a valid user vs an attacker that is just guessing the passwords.</p><p>The goal is to make it easy enough that our systems can compute the password in an acceptable amount of time and resources, but difficult enough that others can not <a href="https://en.wikipedia.org/wiki/Brute-force_attack">brute-force</a> the hashes to find the matching passwords without substantially more resources.</p><h3>Linux passwords</h3><p>Linux has a default password hash of sha512 on most systems but the default password hashing uses a very low number of rounds (5000). On some newer distributions with <a href="https://github.com/linux-pam/linux-pam">PAM</a> version 1.4.0 or greater, the default hash is <a href="https://www.openwall.com/yescrypt/">Yescrypt</a>, which is a better hashing algorithm but still has a default setting of 5 for the number of rounds.</p><p>The default settings hash the password very quickly.</p><pre>$ time echo &quot;123456qwerty&quot; | mkpasswd -m sha512crypt -S &quot;poiuyt098765&quot; -s -R 5000</pre><pre>$6$rounds=5000$poiuyt098765$5DI.fUNj3RZxXlNzjH9umbJLKTkbldWSrlYcCoOgfcdxlD5ZzRN9SHhn.dJ957uaDgI.Z2LEV7s8zpiGH050v/</pre><pre>real 0m0.015s<br>user 0m0.005s<br>sys 0m0.014s</pre><p>However, if we increase the number of rounds we can increase the amount of time to hash a single password. This means we can fine-tune the amount of time that is acceptable based on the sensitivity of the system. The longer it takes for us to hash the password, the longer it takes for an attacker to hash the password.</p><pre>$ time echo &quot;123456qwerty&quot; | mkpasswd -m sha512crypt -S &quot;poiuyt098765&quot; -s -R 3000000</pre><pre>$6$rounds=3000000$poiuyt098765$B4k3B6Iqsbi1SS.R1Cir/l/gV1dTMCoBALETK24A1qek2p.obaTYERHkrgqse5cubbXHPt5v1IfigM0/YzuTD1</pre><pre>real 0m0.934s<br>user 0m0.931s<br>sys 0m0.005s<br></pre><pre>$ time echo &quot;123456qwerty&quot; | mkpasswd -m yescrypt -s -R 11<br>$y$jFT$W8OiEtbvEP6i6zEdUr5vT.$KS6CpfRCq/b0cM0s8YmQvEjRiu0UbOP.j.p9KUAw8U2</pre><pre>real 0m0.915s<br>user 0m0.710s<br>sys 0m0.214s</pre><p>This default can be set in Linux using PAM. This can be in one of several places depending on the operating system and version</p><ul><li>Amazon Linux 2: /etc/pam.d/password-auth (sha512)</li><li>Ubuntu 22.10: /etc/pam.d/common-password (sha512)</li><li>Ubuntu Latest: /etc/pam.d/common-password (yescrypt)</li><li>Debian Buster: /etc/pam.d/common-password (sha512)</li><li>Debian Bullseye: /etc/pam.d/common-password (yescrypt)</li><li>Arch Linux: /etc/pam.d/system-auth (sha512)</li></ul><pre>password  required  pam_unix.so sha512 shadow nullok <strong>rounds=300000</strong></pre><p>or</p><pre>password [success=1 default=ignore] pam_unix.so obscure yescrypt <strong>rounds=11</strong></pre><p>Updating the values and then resetting the password will cause it to be hashed using the new settings.</p><p><em>Note: for Yescrypt the current limit for rounds is </em><em>11 and default of </em><em>5(logarithmic). If you set the number above </em><em>11, it will just set the value to </em><em>5</em></p><h3>Web Applications</h3><p>For any custom applications, You should be using a secure hashing algorithm like <a href="https://en.wikipedia.org/wiki/Argon2">Argon2</a> or <a href="https://en.wikipedia.org/wiki/Scrypt">Scrypt</a>.</p><p>Using the python below, we can run it with different settings to see how long it takes and how hard it is to hash the password. We will start with the default settings and then update and compare the differences. We will only be modifying PasswordHasher() through these different runs.</p><p><em>Note: if you want to test this locally, you will need </em><em>psutil and </em><em>argon2-cffi python packages installed</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e98bc15368da5fc47900c40e2d91a577/href">https://medium.com/media/e98bc15368da5fc47900c40e2d91a577/href</a></iframe><p>With the default settings, we can see that it creates a hash using argon2id with a memory (m) of 65536, a time_cost (t) of 3, and a parallel (p) value of 4. We can increase these values to increase the difficulty to hash the password</p><pre>$ python3 hash_pass.py</pre><pre>$argon2id$v=19$m=65536,t=3,p=4$pIFZByVQozr2AAlBnpxQ1A$1M0lA+JnqNQ+Mwn4l3gVNASwa6RMfnXs4zv7zFcR3+A<br>hash_pass: memory used: 64.0625; exec time: 0.028205156326293945</pre><p>Now if we update the memory and iterations (time_cost) then we can see that it takes much longer to hash the password. ph = PasswordHasher(time_cost=6, memory_cost=2**17) We can see that it increased the requirement from 64M of memory to 128M memory and doubled the iterations. It only took a little over 100ms to run but it still took 4 times longer to complete.</p><pre>$ python3 hash_pass.py</pre><pre>$argon2id$v=19$m=131072,t=6,p=4$aIOnQE1agNRWguLb5qq0xA$JH+k5ilxvGMZw9uy18PenWGBgTg1ohdAA3zy3D3g0MQ<br>hash_pass: memory used: 128.046875; exec time: 0.11450004577636719</pre><p>We can update it again to increase it even more just to see how it does. This time we will go much higher than you normally would for any type of large application. ph = PasswordHasher(time_cost=13, memory_cost=2**19). With this run, it required 512M of memory and with the iterations set at 13, it took just over 1 second to complete. This example took over 35 times longer then the default configuration.</p><pre>$ python3 hash_pass.py</pre><pre>$argon2id$v=19$m=524288,t=13,p=4$Cak8XzZTchf0AdBjFn4lPg$cpg/ysiiDwZBXc/j/7Zo/gde7Zs/YUuGuPrZ03GwWuE<br>hash_pass: memory used: 512.0625; exec time: 1.0690608024597168</pre><p>So by tuning some of these knobs, we can adjust the number of resources required to compute the passwords. Because of these abilities and the ciphers in use, this can reduce the ability for GPUs or FPGAs to be leveraged to crack the password. GPU cracking is many times faster than CPUs for simple hashes but using hashes like argon2id, makes that much more difficult.</p><p><strong>Hash Verification</strong></p><p>We can leverage a similar flow as about for verifying the hash. Using most common trusted libraries, the provided functions for verifying the passwords do most of the heavy lifting and we just provide the hash and the plaintext user input to the function. In the case of argon2-cffi, we just use the verify function from the library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f5f00601377a361633700de0491b3a6/href">https://medium.com/media/1f5f00601377a361633700de0491b3a6/href</a></iframe><p>If you look at the verification above, you can see we are verifying different hashes with the same function and no additional input to the verification process. Since the verification process can validate the password without having to provide the settings directly this allows 2 advantages.</p><ul><li>Allows transparently updating the hash if the cost or memory requirements change</li><li>Allows different users to hash different password difficulties</li></ul><p><strong>Rehashing</strong></p><p>If the hardware that the password validation is running gets replaced with new hardware that is faster, we can update the options for the cipher then we can automatically rehash to the updated parameters upon successful login without any additional actions from the user. With a little example code, we can automatically update the hash and replace the stored value without any additional user interaction.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03f5a2760c947a96cc265e97d62282df/href">https://medium.com/media/03f5a2760c947a96cc265e97d62282df/href</a></iframe><pre>$ python3 rehash.py</pre><pre>$argon2id$v=19$m=65536,t=3,p=4$B/meRi8WYfkPO/RFkG7fGw$whbmpC96PVhKvcNMTNzZlZtVpUhN/Rxbg7BL+Ekufk8</pre><pre>$argon2id$v=19$m=131072,t=6,p=4$AG/nEyYFBqV0oXs2q9dQtg$oR8c/qCL7GWhUuPYsKC3EvrBYdw/5dagRgSXPFRAwxA</pre><p>You can see that after we verify the password hash, we check if we need to rehash the password to increase the difficulty. In this example, the time_cost and memory_cost were both updated so that it would mean that we need to rehash the password. Since we already have the user input from the verify, we can just leverage that and recompute then store the updated hash and improve the security of the passwords anytime we want.</p><p><strong>Different strengths per user</strong></p><p>Since the verification doesn’t need any of the settings, we can still leverage a single verification process but set different difficulties based on the permission set of the user. Since the number of users reduces as the permissions increase, having higher difficulty for higher permissions levels will reduce the impact of the additional resources requirements. Organizations may have thousands of users but only dozens of admins.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff215522e8a500302fc72068550a9211/href">https://medium.com/media/ff215522e8a500302fc72068550a9211/href</a></iframe><p>While this does open up the possibility of seeing which passwords have a stronger hash if they were leaked, then an attacker could potentially directly target those hashes individually if they are targeting a site or applications directly but if they have all the hashes then chances are they also have additional data like roles and other user information.</p><p><strong>Different hardware</strong></p><p>If you have a microservice architecture, you can leverage different hardware for your authentication services to allow increasing the difficulty while helping keep the time low. Attackers try and leverage the fastest hardware possible to break passwords since faster hardware can compute hashes in a shorter period of time.</p><p>If we compare EC2 instances in AWS, an M5 instance has a CPU frequency of 3.1Ghz vs an M5zn instance that has a CPU frequency of 4.5Ghz. This can make a substantial difference in the amount of time to hash a password. In the test below, just by changing the instance type from M5 to M5zn we had a 26.275% decrease in the time it took to compute a single hash. This means we can increase the difficulty of the hash without additional impact on the user logon time.</p><pre># EC2 m5 instance<br>$argon2id$v=19$m=524288,t=14,p=8$iST5wMzirkMqidVSBzymKQ$YxioBey8Amo6EvGU6VtThiUBrwy7YH8vd2YZyXrP3Z8<br>hash_pass: exec time: 1.247293472290039</pre><pre># EC2 m5zn instance<br>$argon2id$v=19$m=524288,t=14,p=8$BKuY7TSTkjoa3mTTylzEPw$pAYjMgsgcuMmXjKIFEKaoWyEZY+BevbEekECeRA4y9A<br>hash_pass: exec time: 0.9195597171783447</pre><h3>Summary</h3><p>While things like Single Sign-On and Multi-Factor authentication are becoming more popular, passwords are not going away anytime soon so we need to make sure we are doing what we can to properly protect them. We know users are not getting better at creating secure passwords so we need to make sure that they are difficult for attackers to attempt to brute force should the hashes get leaked. Ensure that you are using a strong trusted hashing algorithm and <a href="https://security.stackexchange.com/questions/2202/lessons-learned-and-misconceptions-regarding-encryption-and-cryptology/2210#2210"><strong>DO NOT </strong>try and write your own</a>.</p><p>Well-known and trusted libraries are incredibly easy to implement and use. Tuning them can take a bit of time but the protections can pay off in the event of a leak of the password hashes. Take the time to ensure you use a well-tested hashing algorithm that is industry recommended and ensure your systems are not using hashes that are easy to compute or brute force.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b383bbb355df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSL for local development]]></title>
            <link>https://medium.com/@slimm609/ssl-for-local-development-43c9d75c7ee2?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/43c9d75c7ee2</guid>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[cicd]]></category>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Sat, 30 Jul 2022 12:56:35 GMT</pubDate>
            <atom:updated>2022-07-30T12:56:35.922Z</atom:updated>
            <content:encoded><![CDATA[<p>There have been many guides written about using SSL for local development but all of them work off the concept of creating a self-signed root CA, trusting that root CA, then making a certificate based on that CA.</p><p>A quick <a href="https://lmgtfy.app/?q=ssl+certificate+for+local+development">google search</a> for ssl ceritifcates for local development shows a bunch of results</p><ul><li><a href="https://geekflare.com/local-dev-environment-ssl/">https://geekflare.com/local-dev-environment-ssl/</a></li><li><a href="https://web.dev/how-to-use-local-https/">https://web.dev/how-to-use-local-https/</a></li><li><a href="https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/">https://www.freecodecamp.org/news/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec/</a></li><li><a href="https://auth0.com/blog/using-https-in-your-development-environment/">https://auth0.com/blog/using-https-in-your-development-environment/</a></li></ul><p>and the list goes on and on. There are pages and pages on creating self-signed certificates for local development. Still, I have yet to find an article on using valid certificates signed by a public CA for local development.</p><p>Using SSL for development allows for developing and testing in a similar manner to what a production environment would look like. This is not an uncommon setup for developers but it&#39;s still using certificates that are not trusted by default. So why would we want to use a <strong>publicly</strong> trusted CA for local development?</p><ul><li>You can leverage a custom domain for local testing that you own instead of localhost.</li><li>Teams can share the certificate between the whole group of developers instead of each person creating and trusting one individually. (<a href="https://medium.com/@slimm609/securely-storing-secrets-in-git-542771d3ed8c">make sure to share it securely</a>)</li><li>You don’t have to trust a self-signed certificate on each machine.</li><li>Once configured, it works the same that localhost would so CI and pre-merge testing can automatically benefit from it.</li><li>Can support scenarios that require <a href="https://en.wikipedia.org/wiki/Server_Name_Indication">SNI</a> for testing microservices or multiple URLs locally.</li></ul><h3>Requirements</h3><p>In order to use a valid certificate for local development, we must have 2 things.</p><ul><li>A certificate signed by a public CA</li><li>A domain name that we control and can create a valid subdomain.</li></ul><h3>Public Signed Certificate</h3><p>A valid wildcard SSL or certificate with multiple SANs can be generated by following the documented process for the <a href="https://en.wikipedia.org/wiki/Certificate_authority">Certificate Authority</a> (CA) which you are purchasing the certificate from. Sites like <a href="https://www.namecheap.com/security/ssl-certificates/wildcard/">Namecheap</a>, <a href="https://www.digicert.com/tls-ssl/wildcard-ssl-certificates">Digicert</a>, and others all have a similar process. The prices will vary from CA to CA however, since this is only for local development and once configured will not be used anywhere else you don’t need to get any of the “Extra” features that are offered and only need the wildcard certificate itself.</p><p>For this, you should pick an entire subdomain that can be dedicated to development purposes. You can use something like local.mycustomdomain.comand your certificate would be for *.local.mycustomdomain.com</p><h3>DNS</h3><p>We need to create a custom subdomain that we will use for all local development. For this example, I will use AWS <a href="https://aws.amazon.com/route53">Route 53</a>. Using Route 53 for this subdomain is extremely cheap to maintain. A single subdomain and the 1 record we need to create will run $0.50/month for Route 53 hosted zone and 1 million queries per month are $0.40. So the monthly cost with 1 million queries would be less than $1.</p><p>In route 53, create the domain you are going to use then create a wildcard record with an address of 127.0.0.1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fvM7BvhV7S1BSDg0WvtXFA.png" /></figure><p>This means anything that is queried will return the 127.0.0.1address the same way localhost would.</p><pre>$ dig random.local.mycustomdomain.com<br>; &lt;&lt;&gt;&gt; DiG 9.10.6 &lt;&lt;&gt;&gt; random.local.mycustomdomain.com<br>;; global options: +cmd<br>;; Got answer:<br>;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 21762<br>;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 1</pre><pre>;; OPT PSEUDOSECTION:<br>; EDNS: version: 0, flags:; udp: 4096<br>;; QUESTION SECTION:<br>;random.local.mycustomdomain.com. IN A</pre><pre>;; ANSWER SECTION:<br>random.local.mycustomdomain.com. 300 IN A 127.0.0.1</pre><pre>;; AUTHORITY SECTION:<br>local.mycustomdomain.com.  3600 IN NS ns-500.awsdns-62.com.<br>local.mycustomdomain.com.  3600 IN NS ns-1735.awsdns-24.co.uk.<br>local.mycustomdomain.com.  3600 IN NS ns-801.awsdns-36.net.<br>local.mycustomdomain.com.  3600 IN NS ns-1497.awsdns-59.org.</pre><pre>;; Query time: 152 msec<br>;; SERVER: 10.1.2.2#53(10.1.2.2)<br>;; WHEN: Mon Jul 25 20:08:35 EDT 2022<br>;; MSG SIZE  rcvd: 207</pre><h3>Certificate Usage</h3><p>Now that we have the certificate and the custom domain created, we can begin using it for local development and testing.</p><p>Using the cosign-demo repo from a <a href="https://medium.com/@slimm609/image-signing-validation-on-k8s-4b3202dbcd6c">previous post</a>, We can set up nginx ingress on a kind cluster to test and load the <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#tls">TLS</a> certificate into a Kubernetes secret and set up 2 different ingress records</p><pre>$ kubectl get ingress</pre><pre>NAME           CLASS    HOSTS                               ADDRESS        PORTS     AGE<br>kuard-demo-1   &lt;none&gt;   kuard-demo-1.local.mycustomdomain.com   10.96.57.174   80, 443   54m<br>kuard-demo-2   &lt;none&gt;   kuard-demo-2.local.mycustomdomain.com   10.96.57.174   80, 443   54m</pre><pre>$ kubectl get ingress kuard-demo-1 -o yaml</pre><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  annotations:<br>    kubernetes.io/ingress.class: nginx<br>    meta.helm.sh/release-name: kuard-1<br>    meta.helm.sh/release-namespace: default<br>  name: kuard-demo-1<br>  namespace: default<br>spec:<br>  rules:<br>  - host: kuard-demo-1.local.mycustomdomain.com<br>    http:<br>      paths:<br>      - backend:<br>          service:<br>            name: kuard-demo-1<br>            port:<br>              number: 8080<br>        path: /<br>        pathType: Prefix<br>  tls:<br>  - hosts:<br>    - kuard-demo-1.local.mycustomdomain.com<br>    secretName: mycustomdomain-secret</pre><p>The ingress records for kuard-demo-1 and kuard-demo-2 are identical except for the name. With these 2 ingresses, we can validate that they are trusted certificates from the host</p><pre>$ curl -v <a href="https://kuard-demo-1.local.mycustomdomain.com/">https://kuard-demo-1.local.mycustomdomain.com/</a></pre><pre>*   Trying 127.0.0.1:443...<br>* Connected to kuard-demo-1.local.mycustomdomain.com (127.0.0.1) port 443 (#0)<br>* ALPN, offering h2<br>* ALPN, offering http/1.1<br>* successfully set certificate verify locations:<br>*  CAfile: /etc/ssl/cert.pem<br>*  CApath: none<br>* (304) (OUT), TLS handshake, Client hello (1):<br>* (304) (IN), TLS handshake, Server hello (2):<br>* (304) (IN), TLS handshake, Unknown (8):<br>* (304) (IN), TLS handshake, Certificate (11):<br>* (304) (IN), TLS handshake, CERT verify (15):<br>* (304) (IN), TLS handshake, Finished (20):<br>* (304) (OUT), TLS handshake, Finished (20):<br>* SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384<br>* ALPN, server accepted to use h2<br>* Server certificate:<br>*  subject: C=US; ST=Florida; L=Miami; O=mycustomdomain LLC.; CN=*.local.mycustomdomain.com<br>*  start date: Jun 26 00:00:00 2022 GMT<br>*  expire date: June 25 23:59:59 2023 GMT<br>*  subjectAltName: host &quot;kuard-demo-1.local.mycustomdomain.com&quot; matched cert&#39;s &quot;*.local.mycustomdomain.com&quot;<br>*  issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS RSA SHA256 2020 CA1<br>*  SSL certificate verify ok.</pre><p>We can see that it validated the connection from the trusted CA certificates that are already installed on the host and natively works without requiring the addition of a self-signed certificate to the machine&#39;s trust store. Since it is a wildcard certificate we can see that is matched for the subjectAltName and we know the kuard-demo-2 ingress will function the same way and return a valid result as well.</p><h3>Summary</h3><p>Using SSL certificates for local development is becoming more and more common and there are many options for generating self-signed certificates but those solutions do not scale across larger teams without additional actions per team member and additional setups for CI testing pipelines. By using a trusted wildcard certificate, you can support a large number of team members with little maintenance or effort and leverage a common setup for pipeline testing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43c9d75c7ee2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securely storing secrets in Git]]></title>
            <link>https://medium.com/@slimm609/securely-storing-secrets-in-git-542771d3ed8c?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/542771d3ed8c</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[mozilla-sops]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 21:57:05 GMT</pubDate>
            <atom:updated>2022-07-19T21:57:05.378Z</atom:updated>
            <content:encoded><![CDATA[<p>Secrets management and secure storage of secrets as code is always an interesting topic. There are various tools that exist for storing secrets in a Git repository. We will look at several of them that exist and which ones are better or the preferred approach. We will look at several different tools including <a href="https://github.com/elasticdog/transcrypt">transcrypt</a>, <a href="https://github.com/AGWA/git-crypt">git-crypt</a>, <a href="https://git-secret.io/">git-secret</a>, and <a href="https://github.com/mozilla/sops">SOPS</a>. I currently use or have used several of these in the past and have contributed to some, so I will try to share some of my experiences with them.</p><p>Before we dig into each of them, I will say the most flexible and preferred one is SOPS. I will dig into more details of why it’s the best option in my opinion and some recommended configurations for using it. You can jump directly to that <a href="#b544">SOPS</a> section</p><p><a href="https://github.com/bitnami-labs/sealed-secrets">Sealed-secrets</a> is also a common option but it is not covered here because it is restricted to only Kubernetes. Sealed-secrets functions by decryption only by the Kubernetes cluster. The user encrypts a secret that only the cluster can decrypt using a public/private key pair.</p><h3>Repository disclaimer</h3><p>When storing any secrets in a repository even when the files are encrypted, other protections should still be taken. Any repo storing secrets should be a private repo and only grant access to those who need to know. While most of the ciphers in use today are secure when used properly, that does not mean that they will always be. There have been attacks and weaknesses found in ciphers in the past and current ciphers are no exception.</p><p>All the tools here are using well-known and tested tools or libraries for encryption. All of them are generally secure when pushed to the remote repository in their encrypted format given that the passwords or private keys are not compromised.</p><h3>Transcrypt</h3><p><a href="https://github.com/elasticdog/transcrypt">Transcrypt</a> is transparent encryption for git using OpenSSL as the encryption tool. The default cipher is <a href="https://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES-256-CBC</a> but can use any cipher supported by OpenSSL. It uses .gitattributes for determining which files to encrypt/decrypt so you can only encrypt/decrypt a subset of folders or files based on name, path, or regex.</p><pre>$ cat .gitattributes</pre><pre>sensitive_file filter=crypt diff=crypt merge=crypt</pre><pre>$ cat sensitive_file<br>super sensitive secret</pre><p>But once pushed to the repository and viewed by someone that does not have access, the contexts are encrypted.</p><pre>$ cat sensitive_file<br>U2FsdGVkX19KGqMWib3gssm5rnP5LnujJ/G4AvVmvbq2ms5LJ9YmBb772kD85GM+</pre><p>This means it decrypts files on clone/pull and encrypts files on push automatically and requires no additional commands by the user. Transcrypt also supports showing the diff when doing a git diff to see changes between the files.</p><pre>$ diff --git a/sensitive_file b/sensitive_file<br>index f0ff5de..0211c3b 100644<br>--- a/sensitive_file<br>+++ b/sensitive_file<br>@@ -1 +1 @@<br>-super sensitive secret<br>+new super sensitive secret</pre><p>Pros:</p><ul><li>Seamless to the user and does not require additional commands to update files</li><li>A bash script that uses commonly available system tools so it can be included in the repo for all users to easily access.</li><li>Encrypts the entire file contents</li></ul><p>Cons:</p><ul><li>Transcrypt stores the password in plain text in the .git/config file</li><li>The files are stored in plain text on each computer where the repo is checked out and transcrypt has been configured.</li><li>If the .gitattributes is incorrectly changed it can result in sensitive files being pushed to the remote repo in plain text. This would not be as common with single file entries but in a more complex regex configuration.</li></ul><h3>Git-crypt</h3><p><a href="https://github.com/AGWA/git-crypt">Git-crypt</a> is similar to transcrypt and transparent encryption and depends on OpenSSL as well but uses AWS-256-CTR as the encryption algorithm. git-crypt also uses .gitattributes for determining which files to encrypt/decrypt like transcrypt.</p><pre>$ cat .gitattributes</pre><pre>sensitive_file  filter=git-crypt diff=git-crypt</pre><pre>$ cat sensitive_file<br>super sensitive secret</pre><p>Git crypt stores GITCRYPT at the beginning of each file followed by the binary encrypted data when pushed to the repo.</p><pre>$ cat sensitive_file<br>GITCRYPT�b&quot;َp:_��g��lQ0\�_�(��:1�<br>                                 ���rT�</pre><p>This also decrypts on clone/pull and encrypts files on push so the user does not need to run additional commands. Git-crypt both support showing the changes locally with git diff as well.</p><p>Pros:</p><ul><li>Seamless to the user and does not require additional commands to update files</li><li>Uses a better cipher than AES-256-CBC</li><li>Encrypts the entire file contents</li></ul><p>Cons:</p><ul><li>Stores the password in text files in .git/git-crypt/keys/ folder</li><li>Uses a fixed key length when generating the encryption key</li><li>The files are stored in plain text on each computer where the repo is checked out and git-crypt has unlocked the repository.</li><li>If the .gitattributes is incorrectly changed it can result in sensitive files being pushed to the remote repo in plain text. This is the same as transcrypt</li></ul><h3>Git-secret</h3><p><a href="https://git-secret.io/">Git-secret</a> uses GPG instead of OpenSSL for encryption and is not a transparent solution like the others. It uses <a href="https://web.cs.ucdavis.edu/~rogaway/ocb/ocb-faq.htm">AES-256-OCB</a> Git-secret stores the plain text and encrypted versions as 2 different files. The plain text is stored as the original file name and the encrypted version is stored with the extension of .secret. You must also add the plaintext filename to .gitignore to prevent it from being checked into the repo. To add someone with</p><pre>$ cat .gitignore</pre><pre>.gitsecret/keys/random_seed<br>!*.secret<br>sensitive_file</pre><pre>$ cat sensitive_file<br>my secret file</pre><p>Since git-secret stores the encrypted version in a different file, we need to check that file to see the encrypted contents. It stored the .secret version as an encrypted binary file.</p><pre>$ cat sensitive_file.secret<br>��PZ�_yɳ�!�0�K�t���D�1&#39;o|��1-��H��m�ȆT������-�3�` ����v���&amp;d�KA�ͽ΋<br>&lt;&#39;4����sI�8&lt;MO���V�MiB����Gi�C9��ίr2~R��1��_@�PWF7�n=�<br>                                                       �z&lt;]���v�Р</pre><p>Pros:</p><ul><li>Uses AES-256-OCB which is similar to CTR but is an authenticated encryption (this is dependent on the GPG version you are using)</li><li>Uses GPG to share to multiple people natively so a password to protect the private key can (and should) be used.</li></ul><p>Cons:</p><ul><li>Maintains a 2nd copy of each file so there is an easier chance of accidentally checking in a secret file.</li><li>Must add each file to .gitignore so that the source file is not tracked</li><li>Must manually run git secret add $filename (wildcards are supported) for each file you want to encrypt</li></ul><h3>SOPS</h3><p>SOPS stands for <strong>S</strong>ecrets <strong>OP</strong>eration<strong>S</strong> and was developed as an open-source project by Mozilla. SOPS is different than several of the others as it does not encrypt the entire file and only a subset of the contents which are normally considered the sensitive part. This is also the only solution that easily supports storing secrets with different permissions per secret. The encrypted secret contains metadata about who can decrypt the secret so you can have thousands of secrets each with different permissions if needed.</p><p>There are really a few features that make SOPS stand out above all the others.</p><ul><li>All secrets are kept encrypted on disk all the time and you only decrypt the file when you need to e.g sops -d $file.yaml</li><li>SOPS supports <a href="https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing">Shamir’s Secret Sharing</a> Scheme (covered in more detail below)</li><li>Integrations with Terragrunt, helm-secrets, helmfile, Flux, and others.</li></ul><p>We can take an existing plain text file and convert it to a sops encrypted file with sops -e -i $filename. SOPS also has built-in editor support, so you can edit a sops encrypted file by just doing sops $filename and it will open the editor (like vi) with the decrypted contents.</p><pre>$ cat my_secret.yaml</pre><pre>username: my_username<br>password: my_secret_password</pre><p>Once converted to an encrypted file, it encrypts the values of each YAML field in the file, while leaving the keys in plaintext.</p><pre>$ cat my_secret.yaml</pre><pre>username: ENC[AES256_GCM,data:sli5qzAq3tQGGjk=,iv:e3+riN+PjCwJErUDyMqah+QYmLqXOnBzBiraZAakjJA=,tag:lYE/6fVhS5WbzqzQY1rkCw==,type:str]<br>password: ENC[AES256_GCM,data:vGcOkuV/mx3GCLk+heqAUp3e,iv:/77z12Dm6XxAkJ6jbo5wkGWMvRfHECTUEOZgYN3gFZo=,tag:qDkaHadGNjDxLoUuY8lhXQ==,type:str]<br>sops:<br>    kms: []<br>    gcp_kms: []<br>    azure_kv: []<br>    hc_vault: []<br>    age: []<br>    lastmodified: &quot;2022-07-18T21:38:38Z&quot;<br>    mac: ENC[AES256_GCM,data:9IVSULD9o4qeF3fTgXGkJ/Oxm9bmZC08VfuAy41NIXhFtOEuTqKBDNEtQeO27RYKxWZWBBlKnblTdY0Uet9ranQWW586O/uB/Gxnrm9I39p21TGHRv6KVJDRx37lR3IxVdq402N9YkrlHZPjX4WfwsnUCoHqdU6h8+yL48/8EO0=,iv:oZGeCU6zdjq2GQ5tkIdleq0YuoE5QTUTi4q+PnkRZeo=,tag:/kTdQ7czhYyOw4HZ+XvdnA==,type:str]<br>    pgp:<br>        - created_at: &quot;2022-07-18T21:38:38Z&quot;<br>          enc: |<br>            -----BEGIN PGP MESSAGE-----</pre><pre>hF4D7Kht36Nmso4SAQdADtCBr7qHsLWUcj3JIW6cPGNrzrx0oVV7u9qKuQI21jUw<br>            bdMJwE46oJIVzZ3uBYP3vClOvIiOOgVYm7IZERuyzz35uMYYEIgA4DTk6zj0bdoh<br>            1GgBCQIQ+LbJAENuPZa6m8vzoPA4P++uScf2dybKUMDHSTEwGR+bgo4xXKOyinxh<br>            ZlgKXZfoQw5AtK6t7l7hMBt9a5T4lP9rEfB6z3j2s8xwmDbSk1gEJCm7SWWBd6J7<br>            0m5viZUZP9YaUg==<br>            =aaAK<br>            -----END PGP MESSAGE-----<br>          fp: F69F7C85BCBEE72C769BE27DC73DF6C795316F83<br>    unencrypted_suffix: _unencrypted<br>    version: 3.7.3</pre><p>The file stays encrypted until you are ready to actually use the file. Then running a decrypt on the file outputs the contents.</p><pre>$ sops -d my_secret.yaml</pre><pre>username: my_username<br>password: my_secret_password</pre><p>Pros:</p><ul><li>Uses <a href="https://en.wikipedia.org/wiki/Galois/Counter_Mode">AES-256-GCM</a> is an industry-preferred cipher by due to being authenticated encryption and is part of TLS1.2/TLS1.3. Intel has also worked to <a href="https://www.intel.cn/content/dam/www/public/us/en/documents/software-support/enabling-high-performance-gcm.pdf">optimize GCM on intel processors</a> making it faster than several of the other ciphers</li><li>Supports Multi-key operations via Shamir’s Secret Sharing Scheme (See below)</li><li>Files stay encrypted on every machine</li><li>Supports different users/keys per secret</li><li>Supports multiple different types of keys including HSMs like AWS, GCP, and Azure KMS solutions as well as age and gpg encryption.</li><li>Third-party integrations</li></ul><p>Cons:</p><ul><li>SOPS works great with JSON and YAML files but can have problems from time to time with binary data</li><li>Since SOPS only encrypts the value and not the key, it can leak data about the structure or contents of the file. As long as this is accounted for this shouldn’t be a major issue.</li><li>Workflows must be updated to handle runtime decryption instead of just reading plaintext files</li></ul><h3>Shamir’s Secret Sharing in SOPS</h3><p>One of the major benefits of SOPS is the usage of Shamir’s Secret Sharing Scheme. <a href="http://passguardian.com/">PassGuardian</a> has a great online tool that you use to can see it in action. In layman’s terms, it takes a secret value and splits it into a desired number of <strong>shares</strong> and you configure a <strong>threshold,</strong> which is the<strong> </strong>minimum number of shares that must be present in order to reconstruct the secret.</p><p>If we take a secret ofmypasswordand split it into 5 shares with a threshold value of 3, we get</p><pre>801740b2092d05dd9a2b4bbc2e9de1e9cf9a8a0bde090<br>802ac91f42d3d35bdd2a7884179a2e68fb135548560cb<br>803d99ab0bf9f680b706433f0900ff87248edf4418036<br>8044719390ab46c60affba63e10ae9e841a7d8c250e25<br>80532127d981631d60d381d8ff9038079e3a52ce1eed8</pre><p>With these values, it would require <strong>ANY</strong> 3 (or more) values in order to properly reconstruct the original secret. Any less than the configured threshold and reconstruction fails.</p><p>This is implemented in SOPS natively and allows a mix and match of keys from different sources and split the secrets between them. So in the event of a compromise of the single key, the secrets are not compromised.</p><pre>creation_rules:<br>- path_regex: /super_secret/**<br>  shamir_threshold: 3<br>  key_groups:<br>  # 1st key group<br>  - pgp:<br>    - F69F7C85BCBEE72C769BE27DC73DF6C795316F83<br>  # 2nd key group<br>  - kms:<br>    - arn: arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab<br>  # 3rd key group<br>  - age:<br>    - age1l39ptl7udyfqavym4z6hst977xrftxexk9wuzu3jhfyssm0scssssjkdcu</pre><p>This example, uses a PGP key, an AWS KMS key, and an age encryption key. The number of <strong>Shares</strong> is the number of key groups listed and the <strong>Threshold</strong> is determined by the value set for shamir_threshold. Since there are 3 key groups and 3 shares, we know ALL keys must be present in order to decrypt this value. So 2 keys locally on the machine AND valid credentials to talk to AWS KMS service.</p><p>Because of this setup, there are multiple keys that would need to be compromised before the secrets could be decrypted.</p><p><strong>Summary</strong></p><p>Storing secrets in Git repositories is becoming more and more common but people must ensure appropriate controls must be implemented to protect secret data. With employee turnover and things like BYOD (Bring Your Own Device) policies, ensuring that secrets are kept safe is becoming more difficult.</p><p>Using ANY of the options listed here is certainly better than storing secrets in plain text but when it comes to protecting secrets, SOPS just shines above the rest with the choice of ciphers, many different key options, Shamir’s Secret Sharing Scheme, and never storing in unencrypted form on disk.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=542771d3ed8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Instance Profile for local development]]></title>
            <link>https://medium.com/@slimm609/aws-instance-profile-for-local-development-f144b0a7b8b9?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/f144b0a7b8b9</guid>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Fri, 15 Jul 2022 12:30:23 GMT</pubDate>
            <atom:updated>2022-07-15T12:30:23.003Z</atom:updated>
            <content:encoded><![CDATA[<p>There have been several times that I have wanted to test something specific to AWS instance profile but the script or application I was working on is on my local machine. The AWS CLI and SDK’s all support multiple different ways to get credentials and in the <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-precedence">order of precedence</a>,<em> </em>the last one is EC2 instance profile. If you are just making calls to AWS services, you can use environment variables, config files, or command-line flags. However, if you want to use any other fields from the instance metadata or test from something like a docker container, a <a href="https://kind.sigs.k8s.io/">Kind</a> cluster, or a <a href="https://minikube.sigs.k8s.io/docs/">Minikube</a> cluster setting up credentials for each container can be troublesome.</p><p>Amazon provides an open-source tool called <a href="https://github.com/aws/amazon-ec2-metadata-mock">amazon-ec2-metadata-mock</a> that is used to run a web service on a local development machine that we can query to be able to simulate the instance profile metadata endpoint. The problem with the EC2 metadata mock service is that when we start up the mock service it listens on all IPs on the machine but on port 1338 and actual EC2 instances metadata listens on port 80 and IP address of 169.254.169.254, which is a <a href="https://en.wikipedia.org/wiki/Link-local_address">link-local address</a> and most machines do not have any addresses in this range. It also uses fake AWS credentials that can’t be used for any type of connection to AWS.</p><p>But… Let’s see if we can get the ec2-metadata-mock service to serve real credentials and respond like an actual EC2 instance.</p><h3>EC2 metadata mock</h3><p>We can follow the <a href="https://github.com/aws/amazon-ec2-metadata-mock#installation">installation</a> instructions to install the ec2-metadata-mock tool. For the walk-through, I am going to be doing this on macOS but it can also be done on Linux. If you are using Linux, you can substitute darwin for linux and if you are on an arm machine like an M1 mac, then substitute amd64 for arm64.</p><pre>$ curl -Lo ec2-metadata-mock https://github.com/aws/amazon-ec2-metadata-mock/releases/download/v1.11.1/ec2-metadata-mock-darwin-amd64</pre><pre>$ chmod +x ec2-metadata-mock</pre><p>Once we have ec2-metadata-mock installed, we can test it with a few queries.</p><pre>$ ec2-metadata-mock &gt; mock.log &amp;&gt;1 &amp;</pre><pre>$ curl <a href="http://localhost:1338/latest">http://localhost:1338/latest</a>/</pre><pre>dynamic<br>meta-data</pre><pre>$ curl <a href="http://localhost:1338/latest">http://localhost:1338/latest</a>/meta-data/</pre><pre>ami-id<br>...<br>iam/security-credentials<br>iam/security-credentials/baskinc-role<br>instance-id<br>instance-type<br>latest<br>latest/api/token<br>...<br>placement/availability-zone<br>placement/availability-zone-id<br>placement/region<br>public-ipv4<br>security-groups<br>...<br>tags/instance/Name<br>tags/instance/Test</pre><p>You can stop the mock service by killing the background job by using jobs jobs to find the job number and then killing it with the % symbol and job number. e.g. kill %1</p><p>Above we can see that we can query the local service and it looks very similar to what an EC2 instance would return. <em>Note: the ec2-metadata-mock endpoint supports using </em><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html"><em>IMDSv2</em></a><em>, which requires a session token for making calls and can validate them locally. They should be used whenever possible and IMDSv2 is turned on by default but we are not restricting to only IMDSv2 while testing this service locally.</em></p><p>For AWS credentials from EC2 instance profile, they come from the endpoint /latest/meta-data/iam/security-credentials/$role_name. The AWS SDKs makes a call to the /latest/meta-data/iam/security-credentials/ endpoint, which will return the role name (baskinc-role) in the example above. It then takes the role name and adds it to the URL.</p><pre>$ curl <a href="http://localhost:1338/latest">http://localhost:1338/latest</a>/meta-data/iam/security-credentials/baskinc-role</pre><pre>{<br> &quot;Code&quot;: &quot;Success&quot;,<br> &quot;LastUpdated&quot;: &quot;2020-04-02T18:50:40Z&quot;,<br> &quot;Type&quot;: &quot;AWS-HMAC&quot;,<br> &quot;AccessKeyId&quot;: &quot;12345678901&quot;,<br> &quot;SecretAccessKey&quot;: &quot;v/12345678901&quot;,<br> &quot;Token&quot;: &quot;TEST92test48TEST+y6RpoTEST92test48TEST/8oWVAiBqTEsT5Ky7ty2tEStxC1T==&quot;,<br> &quot;Expiration&quot;: &quot;2020-04-02T00:49:51Z&quot;<br>}</pre><h3>Emulating the EC2 metadata endpoint</h3><p><em>I created a </em><a href="https://github.com/slimm609/mock-instance-profile"><em>Github repository</em></a><em> covered in more detail below that will set all of this up but this guide walks through what is happening to emulate local credentials outside of EC2.</em></p><p>Since the EC2 instance metadata endpoint listens on the IP address169.254.169.254 and port 80, we would also have to listen on the same address and port to properly emulate an EC2 instance. We can do this by using aliases or secondary interfaces to add a virtual address to our system on the loopback interface.</p><p>On <strong>macOS</strong>, we can add an alias to the loopback interface with an alternate address.</p><pre>$ sudo ifconfig lo0 alias 169.254.169.254</pre><p>On <strong>Linux</strong>, a secondary loopback interface can be added as shown below.</p><pre>$ sudo ifconfig lo:0 169.254.169.254 netmask 255.255.255.255</pre><h3>Running the Metadata Mock service on the virtual address</h3><p>Now that we have created a virtual address on our system that matches what an EC2 instance would look like, we can start the mock service to listen on the same address and port. We will need to use <a href="https://www.sudo.ws/">sudo</a> command in order to start the service because we are going to make it listen on port 80 which is a <a href="https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html">privileged port</a>.</p><pre>$ ec2-metadata-mock --help</pre><pre>ec2-metadata-mock is a tool to mock Amazon EC2 instance metadata.</pre><pre>Usage:<br>  ec2-metadata-mock &lt;command&gt; [arguments] [flags]<br>  ec2-metadata-mock [command]</pre><pre>Flags:<br>  ...<br>  -n, --hostname string                 the HTTP hostname for the mock url (default: 0.0.0.0)<br>  ...<br>  -p, --port string                     the HTTP port where the mock runs (default: 1338)<br>  ...</pre><pre>Use &quot;ec2-metadata-mock [command] --help&quot; for more information about a command.</pre><p>The output above is trimmed to show the 2 flags we want to pay attention to. We are going to use both -n to set the IP address and -p to set the port to listen on.</p><pre>$ sudo ec2-metadata-mock -n 169.254.169.254 -p 80<br>Password:</pre><pre>2022/07/10 07:33:38 Warning:  Config File &quot;aemm-config&quot; Not Found in &quot;[/Users/test-user]&quot;<br>2022/07/10 07:33:38 Initiating ec2-metadata-mock for all mocks on port 80</pre><pre>Flags:<br>hostname: 169.254.169.254<br>port: 80</pre><p>It will prompt for a password since we need to sudo to bind to port 80.</p><p>We can now query the mock service just like we would on an EC2 instance.</p><pre>$ curl <a href="http://169.254.169.254/latest/">http://169.254.169.254/latest/</a></pre><pre>dynamic<br>meta-data</pre><h3>Generating a working config</h3><p>We now have a working EC2 instance profile running on a local machine and can look up values but we still can’t talk to AWS with this configuration. We need to have valid credentials before we can talk to AWS using the mock instance profile.</p><p>The ec2-metadata-mock has the option to load a config file to serve data from with the -c option and we can generate a starter config with -s which will save it to <em>“$HOME/.ec2-metadata-mock/.aemm-config-used.json”. </em>This gives us a good starting point of what the instance metadata config will look like. We can then generate temporary credentials by using assume-role to inject the credentials into the config before starting the mock service.</p><p>This will give us the ability to natively use EC2 instance profile on the local system and in any docker containers or even kind clusters.</p><p>I have added a repository for the scripts to generate credentials from assume-role, update the config file, then start the mock service. <a href="https://github.com/slimm609/mock-instance-profile">https://github.com/slimm609/mock-instance-profile</a></p><p>If we try and run the aws-cli image before running the mock service, we can see that it fails to find any credentials.</p><pre>$ docker run --rm -it amazon/aws-cli s3 ls</pre><pre>Unable to locate credentials. You can configure credentials by running &quot;aws configure&quot;.</pre><p>However, once we start the mock service it will allow us to talk to AWS just like we are running on an EC2 instance. So we can see we are running on a local MacBook</p><pre>$ uname -a</pre><pre>Darwin slimm609 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101 arm64</pre><p>Now we can start the mock service and provide the role we want to assume and generate credentials for. This only supports assume-role since that is the only option supported for ec2 instances are roles. <em>Note: The session time is currently set to a 1-hour session but an update is in the works to auto-refresh credentials like instance profile. (you can update the time from 3600 to a longer period in the generate_mock_config.py)</em></p><pre>$ ./mock-instance-profile arn:aws:iam::5555555555:role/my-test-role</pre><pre>Password:<br>2022/07/11 21:14:59 Initiating ec2-metadata-mock for all mocks on port 80</pre><pre>Flags:<br>config-file: /Users/test-user/.aws/mock_config.json<br>hostname: 169.254.169.254<br>port: 80</pre><p>Once we start the ec2-metadata-mock service, we can then run the aws-cli container again and see if we get a response.</p><pre>$ docker run --rm -it amazon/aws-cli s3 ls</pre><pre>2022-07-10 20:28:47 instance-profile-mock</pre><pre>$ docker run --rm -it amazon/aws-cli s3 ls s3://instance-profile-mock/</pre><pre>2022-07-10 20:29:15          0 testfile</pre><p>So we can talk to AWS services using the AWS CLI and the AWS SDKs leveraging instance profile the same way we would on an ec2 instance. We can also run the CLI with the debug command to ensure it is using credentials retrieved from the instance profile.</p><pre>$ 2022-07-12 01:38:00,287 - MainThread - urllib3.connectionpool - DEBUG - <a href="http://169.254.169.254/">http://169.254.169.254:80</a> &quot;PUT /latest/api/token HTTP/1.1&quot; 200 44<br>2022-07-12 01:38:00,289 - MainThread - urllib3.connectionpool - DEBUG - <a href="http://169.254.169.254/">http://169.254.169.254:80</a> &quot;GET /latest/meta-data/iam/security-credentials/ HTTP/1.1&quot; 200 12<br>2022-07-12 01:38:00,290 - MainThread - urllib3.connectionpool - DEBUG - <a href="http://169.254.169.254/">http://169.254.169.254:80</a> &quot;GET /latest/meta-data/iam/security-credentials/my-test-role HTTP/1.1&quot; 200 587<br>2022-07-12 01:38:00,291 - MainThread - botocore.credentials - DEBUG - Found credentials from IAM Role: my-test-role</pre><h3>Summary</h3><p>Running EC2 instance profile as a mock service locally allows for testing certain types of workloads without requiring additional resources to be created in AWS. This also allows more native testing of container workloads on development systems.</p><p>The closer you can get to running a development environment like a production environment, the less chance of finding issues further down the road. EC2 instance profile is a great solution for short-lived credentials to access AWS resources but it&#39;s only available in EC2 which makes it difficult for developers to use it early on. Hopefully, this will allow a developer to test closer to how an application would be run in the production environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f144b0a7b8b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Checksec]]></title>
            <link>https://medium.com/@slimm609/checksec-d4131dff0fca?source=rss-79382b3fed79------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4131dff0fca</guid>
            <category><![CDATA[checksec]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Brian Davis]]></dc:creator>
            <pubDate>Sun, 10 Jul 2022 01:22:56 GMT</pubDate>
            <atom:updated>2022-07-10T01:22:56.361Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://slimm609.github.io/checksec.sh/">Checksec</a> is a shell script that can be used to check the properties of binary files in Linux. This can be used to check for several mitigation techniques such as PIE, RELRO, NoExecute, Stack Canaries, ASLR, and others. Checksec can check the Linux kernel to see that certain security features are turned on. When you are compiling source code into binary, there are several security features that can be enabled or disabled during compile time however, most of these features are not on by default when compiling applications and must be set during compile time. The good news is lots of the common upstream projects have adopted these settings over time to become the default for their applications.</p><h3>History</h3><p>In 2009 Tobias Klein released the <a href="https://www.trapkit.de/tools/checksec/">first version</a> of Checksec.sh which he maintained until late 2011. During this time I started using checksec and contributed back some fixes that made it into the last version maintained by Tobias. (<a href="https://www.trapkit.de/tools/checksec/release-notes/1.5/">v1.5</a>). About 2 years later Robin David copied checksec into <a href="https://github.com/RobinDavid/checksec">Github</a> and made some minor updates during the initial commit. In February 2014, I forked the project and started making some updates to the project. Since then I have been the maintainer of the project with contributions and features added from numerous people over the years.</p><h3>Checksec Installation</h3><p><a href="https://github.com/slimm609/checksec.sh">Checksec</a> is maintained on GitHub and can be installed and run on Linux systems. While there are some functions and checks that work on macOS and other BSD systems, it is not generally recommended or supported.</p><p>We can download and install the latest stable version. To verify the file signature you will need OpenSSL installed. You can also get the latest release from <a href="https://github.com/slimm609/checksec.sh/releases">https://github.com/slimm609/checksec.sh/releases</a></p><p>If you are on Linux, you can install it directly.</p><pre>$ CHECKSEC_STABLE=<a href="https://raw.githubusercontent.com/slimm609/checksec.sh/$(curl">$(curl</a> -s <a href="https://api.github.com/repos/slimm609/checksec.sh/releases/latest">https://api.github.com/repos/slimm609/checksec.sh/releases/latest</a> | awk &#39;/&quot;tag_name&quot;/{ print $2 }&#39; | sed &#39;s/&quot;//g;s/,//&#39;)</pre><pre>$ curl -s -o checksec <a href="https://raw.githubusercontent.com/slimm609/checksec.sh/$(curl">https://raw.githubusercontent.com/slimm609/checksec.sh/</a>${CHECKSEC_STABLE}/checksec</pre><pre>$ curl -s -o checksec.sig <a href="https://raw.githubusercontent.com/slimm609/checksec.sh/$(curl">https://raw.githubusercontent.com/slimm609/checksec.sh/</a>${CHECKSEC_STABLE}/checksec.sig</pre><pre>$ curl -s -o checksec.pub <a href="https://raw.githubusercontent.com/slimm609/checksec.sh/$(curl">https://raw.githubusercontent.com/slimm609/checksec.sh/</a>${CHECKSEC_STABLE}/checksec.pub</pre><pre>$ openssl dgst -sha256 -verify checksec.pub -signature checksec.sig checksec</pre><pre>Verified OK</pre><pre>$ chmod u+x checksec</pre><p>If you want to test checksec, you can also do so in a docker container. We will install some tools required for testing as well as some development tools to be able to test some code that we will compile.</p><pre>$ docker run -it ubuntu:latest bash</pre><pre>$ apt install -y build-essential curl procps binutils file golang --no-install-suggests</pre><pre>$ curl -s -o checksec <a href="https://raw.githubusercontent.com/slimm609/checksec.sh/$(curl">https://raw.githubusercontent.com/slimm609/checksec.sh/</a>2.6.0/checksec</pre><pre>$ chmod u+x checksec</pre><p>Once we have it installed, we can run a basic check to ensure that it is working with <em>“./checksec -dir=/bin”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-YnvtUofgD8CZd1cp89mrA.png" /></figure><p>We can see that checksec is working and showing that most of the binaries are compiled with most protections enabled.</p><p>We can create some binaries to check each of these settings individually. We will walk through these in c++, go, and rust. We can see the default settings for the compilers as well.</p><p>C</p><pre>$ cat &gt; hello.c &lt;&lt; EOF<br>#include &lt;stdio.h&gt;<br>int main() {<br>   // printf() displays the string inside quotation<br>   printf(&quot;Hello, World!&quot;);<br>   return 0;<br>}<br>EOF</pre><pre>$ gcc hello.c -o c_hello</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ccox60tsjsw3zvjb-POk_Q.png" /><figcaption>Default C binary</figcaption></figure><p>Go</p><pre>$ cat &gt; hello.go &lt;&lt; EOF<br>package main<br>import &quot;fmt&quot;<br>func main() {<br>    fmt.Println(&quot;hello world&quot;)<br>}<br>EOF</pre><pre>$ go build -o go_hello hello.go</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*65qX3mR8qe29SBAF8XAZ1A.png" /><figcaption>Default Golang binary</figcaption></figure><p>Rust</p><pre>$ cat &gt; hello.rs &lt;&lt; EOF<br>fn main() {<br>    // Statements here are executed when the compiled binary is called</pre><pre>// Print text to the console<br>    println!(&quot;Hello World!&quot;);<br>}<br>EOF</pre><pre>$ rustc -o rs_hello hello.rs</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DDDpw62lHiRuELNy0xvW6w.png" /><figcaption>Default Rust binary</figcaption></figure><p>So we can see there are some differences in the default options for each language.</p><h3>No-Execute (NX)</h3><p>No-Execute is a technology used in CPUs to split areas of memory into 2 sections: storage of code and storage of data. This splits up what should be executed as program code and what should be read as program data. The program data is changed to remove the executable permissions from that section of memory so that no user data can be executed as application code.</p><p>This technology is built into the CPU itself and on most common systems it is enabled by default. This can be seen in the images above. We can recompile each program to turn off the NX bit. <em>Note: This is turned off only for demonstration purposes and we would not want to turn this off normally.</em></p><pre>$ rustc -o output/rs_hello -Clink-arg=-Wl,-z,execstack hello.rs</pre><pre>$ go build -ldflags &#39;-linkmode=external -extldflags &quot;-Wl,-z,execstack&quot;&#39; -o output/go_hello hello.go</pre><pre>$ gcc -Wl,-z,execstack hello.c -o output/c_hello</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qGK6ShPaoSoG5-pqOaqPEA.png" /><figcaption>Disable NX Bit</figcaption></figure><p>We can see by the output that the NX bit has been disabled for each binary. This means none of the CPU No-Execute protections would be applied to any of these binaries</p><h3>Position Independent Executable (PIE)</h3><p>Executable Linkable Format (ELF) files have a fixed base address space and must be loaded in that address space during execution. Dynamic executables are normally position-dependent and require fixed address space in memory. <a href="https://en.wikipedia.org/wiki/Position-independent_code#Position-independent_executables">Position Independent Executables</a> are binaries made from Position Independent Code (PIC) which differs from traditional code in the functions used to access code and data objects via an indirect access table. This table is the Global Offset Table, which contains the addresses of functions and objects exported by the shared libraries. This allows binaries to take advantage of Address Space Layout Randomization. Position Independent Executables originated from part of the PaX project’s <a href="https://pax.grsecurity.net/docs/randexec.txt">randexec</a>.</p><pre>$ gcc -fPIE -pie  hello.c -o output/c_hello</pre><pre>$ rustc -o output/rs_hello -Crelocation-model=pie hello.rs</pre><pre>$ go build -buildmode=pie -ldflags &#39;-linkmode=external&#39; -o output/go_hello hello.go</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60M32MmJO6iy7dTdnIEtqw.png" /><figcaption>PIE enabled</figcaption></figure><p>We can see that all 3 binaries now have PIE enabled.</p><h3>Address Space Layout Randomization (ASLR)</h3><p><a href="https://en.wikipedia.org/wiki/Address_space_layout_randomization">Address Space Layout Randomization</a> is a security technique that is used to help prevent or reduce the chances of application exploits. Address Space Layout Randomization prevents an attacker from reliably jumping to a specific location or function in memory. ASLR randomizes the address space of several areas of the process. While there are exploits that can get around the protections provided by ASLR, it has been effective in helping to reduce the chances of many common exploits and is included in Linux, Windows, macOS, BSD, and others. It is also enabled by default on iOS and Android. The <a href="https://pax.grsecurity.net/">PaX team</a> published the <a href="https://pax.grsecurity.net/docs/aslr.txt">first design</a> of ASLR in 2001 as well as the design for <a href="https://pax.grsecurity.net/docs/noexec.txt">noexec</a>.</p><p>For individual binaries, there are not any flags that need to be turned on but we can check the kernel to see that ASLR is turned on. In the picture below, we can see that <em>Vanilla Kernel ASLR </em>is set to <em>“</em><strong><em>Full</em></strong><em>” </em>so we can verify that the ASLR is turned on.</p><p>If it is not turned on it can be with <em>“sysctl”</em></p><ul><li>0 = ASLR is disabled</li><li>1 = ASLR randomization of the stack, virtual dynamic shared object (VDSO) page, and shared memory regions</li><li>2 = ASLR randomization of the stack, VDSO page, shared memory regions, and data segments</li></ul><pre>$ sysctl -w kernel.randomize_va_space=2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*26ACNR9EdnrwtkdLWe9AoQ.png" /><figcaption>Docker kernel config</figcaption></figure><h3>Relocation Read-Only (RELRO)</h3><p>A dynamically linked Executable Linkable Format (ELF) binary uses a look-up table called <a href="https://en.wikipedia.org/wiki/Global_Offset_Table">Global Offset Table</a> (GOT) to dynamically resolve functions. The GOT lives in a predefined place and is writable by default so an attacker just needs to be able to write a few bytes to a controlled place in memory in order to exploit this and allow arbitrary code execution. Relocation Read-Only can be enabled to mitigate this security weakness. The security property makes the GOT within the binary read-only, which prevents some types of relocation attacks. This forces the linker to resolve all dynamically linked functions at the beginning of execution and then changes the Global Offset Table to read-only. There are 2 modes of RELRO, Full and Partial. Under Partial RELRO, only the Global Offset Table is marked as read-only but for Full RELRO both the Global Offset Table and the Procedure Linkage Table are both marked as read-only.</p><p>To enable RELRO on binaries, we use the flags of “-z,relro” for partial RELRO and “-z,relro,-z,now” for full RELRO. Most systems have started to enable at least some level of RELRO as a default flag when compiling.</p><pre>$ rustc -o output/rs_hello -Clink-arg=-Wl,-z,relro,-z,now hello.rs</pre><pre>$ go build -ldflags &#39;-linkmode=external -extldflags &quot;-Wl,-z,relro,-z,now&quot;&#39; -o output/go_hello hello.go</pre><pre>$ gcc -Wl,-z,relro,-z,now hello.c -o output/c_hello</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jaLcNBQogjhwOyjs7MzIjg.png" /><figcaption>Full RELRO</figcaption></figure><p>Now that we have compiled all 3 with RELRO, we can see they all show <em>“Full RELRO”</em> is enabled.</p><h3>Stack Smashing Protection (SSP)</h3><p>Stack smashing protections were first implemented back in 1997 by StackGuard and were published for the <a href="https://www.usenix.org/legacy/publications/library/proceedings/sec98/full_papers/cowan/cowan.pdf">7th USENIX Security Symposium</a> in Jan 1998 and was first introduced as patches to GCC in 2.7 for x86. For a few years, StackGuard and IBM both worked on stack-smashing protection before Red Hat identified some problems and re-implemented SSP which then made it into GCC in version 4.1 as “<em>-fstack-protector”</em> and <em>“-fstack-protector-all”</em> flags. In GCC version 4.9 a new option was added called <em>“-fstack-protector-strong” </em>that provides better protection than<em> “-fstack-protector” </em>but not as much as<em> “-fstack-protector-all” </em>in the interest of performance.</p><p>Stack-smashing protection uses canaries, predetermined values inserted between the memory buffer, and control data on the stack to monitor buffer overflows. When an application executes, memory gets allocated to the process. A portion of the memory is called the stack, which is simply a data structure with two operations: push and pop, which adds and removes data onto the stack. Malicious input can overflow and/or corrupt the stack which can cause the program to crash or return memory to the attacker. Enabling Stack Canaries can help prevent these by inserting a predetermined random value at the end of the stack which gets validated before execution. If there is an overflow, the random value will get pushed further down the memory segment and will not pass the validation checks for the canary. <em>Note: stack-protector is still experimental in rust</em></p><pre>$ gcc -fstack-protector-all hello.c -o output/c_hello</pre><pre>$ rustc -o output/rs_hello -Z stack-protector=all hello.rs</pre><pre>$ go build -buildmode=pie -ldflags &#39;-linkmode=external&#39; -o output/go_hello hello.go</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_-rZua0f_gQZ3IEjo7xRw.png" /><figcaption>Stack Canaries enabled</figcaption></figure><h3>Fortify Source (FORTIFY_SOURCE)</h3><p><a href="https://gcc.gnu.org/legacy-ml/gcc-patches/2004-09/msg02055.html">Fortify Source</a> is a feature of GLIBC and GCC used to help detect and prevent several known classes of buffer overflows. When enabling Fortify Source during compile time, the compiler will perform some automatic bounds checking on certain functions to prevent simple buffer overflows. This is performed by static and dynamic checks on the buffer size.</p><p>Rust is not included in this one. It does not currently look like there is a way to utilize FORTIFY_SOURCE with rust. Rust does not currently support setting CFLAGS that can be used by the compiler that I could find. <em>Note: if you know how to pass custom cflags to the llvm that runs behind rust, please let me know and I will investigate getting “D_FORTIFY_SOURCE=2&quot; working in rust</em></p><pre>$ gcc -D_FORTIFY_SOURCE=2 -O2 hello.c -o output/c_hello</pre><pre>$ CGO_CPPFLAGS=&quot;-D_FORTIFY_SOURCE=2&quot; go build -buildmode=pie -ldflags &#39;-linkmode=external&#39; -o output/go_hello hello.go</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zv_u66V8pqqn6mc8eb2pAg.png" /><figcaption>Fortify Source</figcaption></figure><h3>Symbols</h3><p>By default, symbols are on for binaries. These symbols can be beneficial for debugging but should be turned off on any code that will be released to an environment. This also helps reduce the space of each binary. If the binary was not stripped during compile to remove the symbols, it can be done after the fact with the “strip” command. It may be common to leave them on during development but make sure they are turned off before the final release of a binary.</p><pre>$ gcc -s hello.c -o output/c_hello</pre><pre>$ rustc -o output/rs_hello -C strip=symbols hello.rs</pre><pre>$ go build -ldflags &#39;-s&#39; -o output/go_hello hello.go</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yitIl4cgoieyOEzPmDvmnA.png" /><figcaption>Symbols removed</figcaption></figure><p>You can see that removing these symbols can reduce the file size greatly in some cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*qvZjcmTFrHZbr1CMexa38Q.png" /><figcaption>Symbols included in binaries</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*r8TfRmjv26n3Z11k-2O6JQ.png" /><figcaption>Symbols removed in binaries</figcaption></figure><h3>Putting it all together</h3><p>Throughout the guide, there are several different flags that can be set that can impact the security level of the binaries. These will ultimately provide a level of additional security above the standard features when the binary is actually compiled. While none of them are perfect, a part of security is about ensuring a defense-in-depth posture to help reduce the risk of vulnerabilities.</p><pre>$ CGO_CPPFLAGS=&quot;-D_FORTIFY_SOURCE=2&quot; go build -buildmode=pie -ldflags &#39;-linkmode=external -s -extldflags &quot;-Wl,-z,relro,-z,now,-z,noexecstack&quot;&#39; -o output/go_hello hello.go</pre><pre>$ rustc -o output/rs_hello -Z stack-protector=all  -Clink-arg=-Wl,-z,relro,-z,now -Clink-arg=-Wl,-z,noexecstack -C strip=symbols -Crelocation-model=pie hello.rs</pre><pre>$ gcc -fPIE -pie -Wall -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 hello.c -s -Wl,-z,relro,-z,now -Wl,-z,noexecstack -o output/c_hello</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q_AJsggNqD83GhhYh3S0dw.png" /><figcaption>All together now</figcaption></figure><h3>Future improvements</h3><p>Some newer technologies like stack-clash-protection and fcf-protection which can provide additional binary protections. These features and other improvements are in the works but take time to understand how to detect when they are enabled or disabled. Stay tuned for more updates on these features.</p><h3>Summary</h3><p>Binary security features added during compilation are often an overlooked area by most but can be a critical part of defense-in-depth and improving the overall security posture of your applications. While there are some caveats depending on where and how the binaries are being used, if you can deal with the additional requirements then the final images will provide additional protections around common attacks.</p><h3>Additional Reading</h3><p><a href="https://doc.rust-lang.org/rustc/exploit-mitigations.html">https://doc.rust-lang.org/rustc/exploit-mitigations.html</a><br><a href="https://doc.rust-lang.org/rustc/codegen-options/index.html">https://doc.rust-lang.org/rustc/codegen-options/index.html</a><br><a href="https://wiki.gentoo.org/wiki/Hardened/Introduction_to_Position_Independent_Code">https://wiki.gentoo.org/wiki/Hardened/Introduction_to_Position_Independent_Code</a><br><a href="https://pax.grsecurity.net/docs/">https://pax.grsecurity.net/docs/</a><br><a href="https://blog.osiris.cyber.nyu.edu/exploitation%20mitigation%20techniques/exploitation%20techniques/2011/06/02/relro-relocation-read-only/">https://blog.osiris.cyber.nyu.edu/exploitation%20mitigation%20techniques/exploitation%20techniques/2011/06/02/relro-relocation-read-only/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4131dff0fca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>