<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>owasp Archives - Tech Chronicles</title>
	<atom:link href="http://kostacipo.stream/tag/owasp/feed/" rel="self" type="application/rss+xml" />
	<link>https://kostacipo.stream/tag/owasp/</link>
	<description>Ramblings of a Tech Dude</description>
	<lastBuildDate>Wed, 08 Jan 2020 10:57:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://kostacipo.stream/wp-content/uploads/2019/12/cropped-profile-32x32.jpg</url>
	<title>owasp Archives - Tech Chronicles</title>
	<link>https://kostacipo.stream/tag/owasp/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Creating a Secure Pipeline: Jenkins with SonarQube and DependencyCheck</title>
		<link>http://kostacipo.stream/creating-a-secure-pipeline-jenkins-with-sonarqube-and-dependencycheck/</link>
					<comments>http://kostacipo.stream/creating-a-secure-pipeline-jenkins-with-sonarqube-and-dependencycheck/#respond</comments>
		
		<dc:creator><![CDATA[Majordomo]]></dc:creator>
		<pubDate>Wed, 08 Jan 2020 10:45:34 +0000</pubDate>
				<category><![CDATA[DevOps]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ci/cd]]></category>
		<category><![CDATA[jenkins]]></category>
		<category><![CDATA[owasp]]></category>
		<category><![CDATA[sonarqube]]></category>
		<guid isPermaLink="false">http://www.kostacipo.stream/?p=1639</guid>

					<description><![CDATA[<p>&#160; Configuring Jenkins To Build WebGoat We&#8217;re going to scan a known vulnerable webapp, WebGoat, which is an OWASP project used for learning basic web penetration testing skills and vulnerabilities. A good scanner should find a lot of things! A quick note: We were initially going to use Mutillidae, another vulnerable app written in PHP. [&#8230;]</p>
<p>The post <a href="http://kostacipo.stream/creating-a-secure-pipeline-jenkins-with-sonarqube-and-dependencycheck/">Creating a Secure Pipeline: Jenkins with SonarQube and DependencyCheck</a> appeared first on <a href="http://kostacipo.stream">Tech Chronicles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<h2 id="configuring-jenkins-to-build-webgoat">Configuring Jenkins To Build WebGoat</h2>
<p>We&#8217;re going to scan a known vulnerable webapp, <a href="https://webgoat.github.io/WebGoat/">WebGoat</a>, which is an OWASP project used for learning basic web penetration testing skills and vulnerabilities. A good scanner should find a lot of things!</p>
<p>A quick note: We were initially going to use <a href="https://github.com/webpwnized/mutillidae">Mutillidae</a>, another vulnerable app written in PHP. However we couldn&#8217;t find any good open source PHP Static analyzers that would catch the vulnerabilities. </p>
<p>Anyway, let&#8217;s get on with Jenkins. Navigate in your browser to <a href="http://localhost:8080">http://localhost:8080</a> and enter the admin password shown in the terminal running docker. Go ahead and install the default plugins (for a deployed instance, I would recommend only installing plugins you will actually use) and create your first admin user.</p>
<p>WebGoat requires Java 11 to build, which Jenkins won&#8217;t install automatically. Head over to the main page -&gt; Manage Jenkins -&gt; Global Tool Configuration. There are two sections here we will update now: JDK installation and Maven installations. We need to add a link to a Java 11 installer &#8211; we used <a href="https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz">https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz</a> and we can use the default maven. Your config should look like this:</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img decoding="async" class="kg-image" src="https://nullsweep.com/content/images/2019/05/jenkins_jdk_install_config.png"><figcaption>Jenkins JDK11 Install configuration</figcaption></figure>
<figure class="kg-card kg-image-card kg-card-hascaption"><img decoding="async" class="kg-image" src="https://nullsweep.com/content/images/2019/05/jenkins_maven_install_config.png"><figcaption>Jenkins Maven install configuration</figcaption></figure>
<p>We sometimes see Jenkins have trouble installing a JDK this way if more than one JDK is installed in the system. If this is the first one, there should be no problems.</p>
<p>Finally, we have to set the JAVA_HOME variable. In the Jenkins -&gt; Manage Jenkins -&gt; Configure System menu, enable environment varaibles and set JAVA_HOME equal to /var/jenkins_home/tools/hudson.model.JDK/openjdk11/jdk-11.0.1/.</p>
<p>Now let&#8217;s create a pipeline for WebGoat and make sure it builds successfully. Back on the main page choose new item -&gt; freestyle project.</p>
<p>The initial setup is pretty simple:</p>
<ul>
<li>Add Webgoat to the various github setting locations (https://github.com/WebGoat/WebGoat/)</li>
<li>Set the target branch to */develop</li>
<li>Create a maven build step (&#8220;Invoke top level maven targets&#8221;) and give it the command &#8220;clean install&#8221;</li>
</ul>
<p>Here is the full pipeline configuration:</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img decoding="async" class="kg-image" src="https://nullsweep.com/content/images/2019/05/initial_webgoat_pipeline.png"><figcaption>Basic WebGoat Pipeline</figcaption></figure>
<p>Try running it and making sure that everything builds successfully.</p>
<h2 id="adding-sonarqube-and-dependencycheck">Adding SonarQube and DependencyCheck</h2>
<h3 id="sonarqube-setup-security">SonarQube setup &amp; security</h3>
<p>We already have a SonarQube instance running, we just need to link and configure Jenkins to use it. Log in to <a href="http://localhost:9000">http://localhost:9000</a> and use the default sonarQube login of admin/admin.</p>
<p>Although this is only for practice, I still want to secure our SonarQube instance, so do the following:</p>
<ul>
<li>Change the admin password</li>
<li>Go to administration-&gt; security and turn on &#8220;Force user authentication&#8221;</li>
<li>Create a new user for Jenkins.</li>
<li>Log into the new user, go to the profile -&gt; security section, and generate a token. Copy this for later use.</li>
</ul>
<p>Finally, create a project named &#8220;webgoat&#8221; with your jenkins user.</p>
<h3 id="configure-the-plugins-for-jenkins">Configure the plugins for Jenkins</h3>
<p>We will need two new plugins for jenkins. In the Jenkins home page, go to Mange Jenkins -&gt; Manage Plugins. On the Available tab find and select &#8220;OWASP Dependency-Check Plugin&#8221; and &#8220;SonarQube Scanner for Jenkins&#8221;. Install them without restarting.</p>
<p>Back on the Jenkins home, go to Manage Jenkins -&gt; Global Tool Configuration. You should see a new option for SonarQube Scanner. Add an installation here (I just chose the latest from Maven Central) and save.</p>
<p>Finally, head over to Jenkins -&gt; Manage Jenkins -&gt; Configure System and add a sonarqube instance. The URL with our docker container is http://sonarqube:9000 and the token should be the one you saved while setting up the Jenkins user in SonarQube. Here is my setup:</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img decoding="async" class="kg-image" src="https://nullsweep.com/content/images/2019/05/sonarqube_settings.png"><figcaption>SonarQube Settings</figcaption></figure>
<p>One other thing I had to do to get SonarQube working properly. For some reason I couldn&#8217;t completely determine, the SonarQube startup script was truncating the JAVA_HOME path incorrectly, causing errors during the pipeline. To solve this, log into the docker container manually and update the sonar script to the proper JAVA_HOME.</p>
<pre class=" language-bash"><code class=" language-bash">$ docker <span class="token function">exec</span> -it secure_pipeline_jenkins_1 <span class="token function">bash</span>
jenkins@2ea0acb5905d:/$ <span class="token function">cd</span> /var/jenkins_home/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube
jenkins@2ea0acb5905d:~/tools/hudson.plugins.sonar.SonarRunnerInstallation/sonarqube$ <span class="token function">head</span> bin/sonar-scanner
<span class="token comment">#!/bin/sh</span>
<span class="token comment">#</span>
<span class="token comment"># SonarQube Scanner Startup Script for Unix</span>
<span class="token comment">#</span>
<span class="token comment"># Optional ENV vars:</span>
<span class="token comment">#   SONAR_SCANNER_OPTS - Parameters passed to the Java VM when running the SonarQube Scanner</span>
<span class="token comment">#   SONAR_SCANNER_DEBUG_OPTS - Extra parameters passed to the Java VM for debugging</span>
<span class="token comment">#   JAVA_HOME - Location of Java's installation</span>

JAVA_HOME<span class="token operator">=</span><span class="token string">"/var/jenkins_home/tools/hudson.model.JDK/openjdk11-remote/jdk-11.0.1"</span>
</code></pre>
<h3 id="add-sonarqube-and-dependencycheck-to-the-pipeline">Add SonarQube and DependencyCheck to the pipeline</h3>
<p>Now we can add these to our pipeline and start scanning with every build.</p>
<p>In the pipeline created earlier, add two new build steps &#8211; Invoke Dependency-Check analysis and Execute SonarQube Scanner. In the SonarQube scanner, add the configuration settings required &#8211; the project key and name should match the project you created in SonarQube.</p>
<pre class=" language-bash"><code class=" language-bash">sonar.projectKey<span class="token operator">=</span>webgoat
sonar.projectName<span class="token operator">=</span>webgoat
sonar.projectVersion<span class="token operator">=</span>1.0
sonar.language<span class="token operator">=</span>java
sonar.java.binaries<span class="token operator">=</span>**/target/classes
sonar.exclusions<span class="token operator">=</span>**/*.ts
</code></pre>
<p>I am excluding the TypeScript files above since we did not setup Node or a JS build step for our project. In a real project, we would want to ensure that they were also scannable.</p>
<p>In the DependencyCheck advanced section, check to generate HTML reports as well for easier viewing.</p>
<p>Here is my full pipeline configuration now:</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img decoding="async" class="kg-image" src="https://nullsweep.com/content/images/2019/05/webgoat_pipeline_with_sast.png"><figcaption>Full Secure Pipeline</figcaption></figure>
<p>Kick off a build and make sure it runs correctly. Afterwards, you should be able to see results.</p>
<h3 id="viewing-reports">Viewing Reports</h3>
<p>If all runs successfully, logging into SonarQube will show you security scan details (with plenty of findings!) and the pipeline can show you the dependencyCheck results in the workspace -&gt; dependency-check-report.html file.</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img decoding="async" class="kg-image" src="https://nullsweep.com/content/images/2019/05/dependencyCheck_results.png"><figcaption>DependencyCheck Sample Data</figcaption></figure>
<figure class="kg-card kg-image-card kg-card-hascaption"><img decoding="async" class="kg-image" src="https://nullsweep.com/content/images/2019/05/webgoat_sonarqube_report.png"><figcaption>SonarQube Findings</figcaption></figure>
<p>You can and should at this point consider additional SonarQube plugins (or other SAST tools) that are specifically for your languages and frameworks.</p>
<h2 id="breaking-the-build">Breaking the Build</h2>
<p>We want to know when something isn&#8217;t working right at the build phase. SonarQube gives us this for free with the plugin (you should see a nice red ERROR tag under the SonarQube Quality gate) but DependencyCheck requires one more configuration.</p>
<p>Add a post-build check for &#8220;Publish Dependency Check Results&#8221; and expand the advanced tabs. Just add some threshold data and the build will fail or be marked unstable according to the rules set.</p>
<p>Here &nbsp;is our final pipeline configuration, fully expanded.</p>
<figure class="kg-card kg-image-card"><img decoding="async" class="kg-image" src="https://nullsweep.com/content/images/2019/05/jenkins_full_sast.png"></figure>
<h2 id="final-thoughts">Final Thoughts</h2>
<p>Getting a CI/CD pipeline running with some basic security checks can be done within a few minutes. This will help keep your published artifacts in better shape and ensure the team has an opportunity to learn about security issues as soon as they emerge.</p>
<p>The post <a href="http://kostacipo.stream/creating-a-secure-pipeline-jenkins-with-sonarqube-and-dependencycheck/">Creating a Secure Pipeline: Jenkins with SonarQube and DependencyCheck</a> appeared first on <a href="http://kostacipo.stream">Tech Chronicles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://kostacipo.stream/creating-a-secure-pipeline-jenkins-with-sonarqube-and-dependencycheck/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
