# Creating TeamCity Projects

### Module Objectives

* Pulling Public Repositories from GitHub
* Pulling Private Repositories from GitLab

### Introduction

TeamCity's projects consist of repositories pulled from public and private sources such as an internal GitLab server, or GitHub. By default, TeamCity will check for updates from the repository every 60 seconds, then pull the latest changes - though this can be changed per project if this is not something that you want/need.

You can also select which branches to pull from - either the default main branch, all branches (by inserting a wildcard `*`), or a specific branch such as `dev` or `nightly` if you're looking for bleeding edge changes.&#x20;

### Public Repositories

{% tabs %}
{% tab title="C# Tools" %}

* [Rubeus](https://github.com/GhostPack/Rubeus)
* [Seatbelt](https://github.com/GhostPack/Seatbelt)
* [SafetyKatz](https://github.com/GhostPack/SafetyKatz)
* [SharpUp](https://github.com/GhostPack/SharpUp)
* [SharpDpapi](https://github.com/GhostPack/SharpDPAPI)
  {% endtab %}

{% tab title="Golang Tools" %}

* [Ligolo-ng](https://github.com/Nicocha30/ligolo-ng)
* [Trufflehog](https://github.com/trufflesecurity/trufflehog.git)
  {% endtab %}
  {% endtabs %}

#### Creating your public project

To create our project, first get a GitHub link (We will use Seatbelt and Ligolo-ng for our demo). On TeamCity, select ***Create Project -> From a repository URL -> \<REPOSITORY LINK> -> Proceed***

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FEW9kSQfDYHJyIPWVBOkG%2Fimage.png?alt=media&#x26;token=8e52ebcf-e87e-4d9a-939f-7e14800175b9" alt=""><figcaption><p>Create Project -> Seatbelt</p></figcaption></figure>

{% hint style="info" %}

* Make sure you have an internet connection to your server
* Add a username and token if you are pulling from a private repository
  {% endhint %}

Next, change the builder configuration name to something memorable or related to the project, and add the branch that you would like to monitor. You can go to the original project's repository to see what the other branches are. Once you're ready, click proceed.

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2Fpey9Q8gHa4FetcIaZir2%2Fimage.png?alt=media&#x26;token=1e16ab8c-cbd8-44a6-81b6-76f9f4da115b" alt=""><figcaption><p>TeamCity Project Setup</p></figcaption></figure>

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2Fn32tUW1PRNJq4mX9uDS7%2Fimage.png?alt=media&#x26;token=b2a58cd8-16f7-45c1-aa00-d90a1c02c05e" alt=""><figcaption><p>Seatbelt GitHub Repository</p></figcaption></figure>

After clicking proceed, you will be met with the configuration page for our builder. TeamCity will automatically detect a build step to use based on our project, but we can change this later

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FJyRMNJajqvsDBNfhXcSH%2Fimage.png?alt=media&#x26;token=369a7fa6-f075-4d22-af4b-a9d1aba6b009" alt=""><figcaption><p>TeamCity build step detection</p></figcaption></figure>

Use the selected build step, then click on edit next to the .NET builder

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FcFXvNrLlEd8UnMFumNv8%2Fimage.png?alt=media&#x26;token=e6e4f5df-4064-4624-890f-9245d3100c1e" alt=""><figcaption><p>Editing the build step</p></figcaption></figure>

The compile instructions on Seatbelt tells us to use .NET 3.5 or 4.0 to build our project, and to target release. We will reflect these requirements in our build step.

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FG4Dc767WUJptSJSQnfkV%2Fimage.png?alt=media&#x26;token=77200777-8834-447b-9443-5c37e9b24a52" alt=""><figcaption><p>Seatbelt Compile Instructions</p></figcaption></figure>

1. Set the MSBuild Version to 2019
2. Set the Required SDK to `3.5` or `4.0`
3. Set the Configuration to `Release`
4. Save your changes

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FKWIrVNFU30Z5T9kZlHJE%2Fimage.png?alt=media&#x26;token=f3ecffd2-0fcf-498a-b2e5-5593e7fdb16a" alt=""><figcaption><p>.NET build step</p></figcaption></figure>

Now, we need to specify where our binary will be built. We will choose `Seatbelt\bin\Release\Seatbelt.exe`&#x20;

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FAm0CHuGUo6JpJPoUeAPu%2Fimage.png?alt=media&#x26;token=29da95cc-bc99-4f01-a7a8-9acdb1e4311d" alt=""><figcaption><p>Artifact Path</p></figcaption></figure>

#### Troubleshooting

{% hint style="warning" %}

* Double check that JDK 17 or 22 are installed on your system
* If you do not have any agents, then you can click on Agents from the dashboard, click on Install Agent, then follow the instructions
  {% endhint %}

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FQempW1RQKvP4JgNgTka9%2Fimage.png?alt=media&#x26;token=8e5e770e-2949-4d5f-90c4-c19cb0c6120d" alt=""><figcaption><p>Install Agent</p></figcaption></figure>

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FyVns5jaWQjahTo9qCG00%2Fimage.png?alt=media&#x26;token=ca0f83d9-8289-4b88-b6d3-610d092bd0d8" alt=""><figcaption><p>Agent Download URL</p></figcaption></figure>

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FUKOl1Vli2xRziP3eiwZl%2Fimage.png?alt=media&#x26;token=78e6fb4e-b26d-463c-881d-70f4aed087c2" alt=""><figcaption></figcaption></figure>

#### Cont.

If everything went well, you should be able to run your build step, and get your first artifact!

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FnE8DiV3EVjvFBVrnsxQB%2Fimage.png?alt=media&#x26;token=96fd08c8-c3b1-4870-a69c-d29d4f4bb257" alt=""><figcaption><p>Running the build step</p></figcaption></figure>

{% hint style="warning" %}
If you run into an error on .NET SDK 3.5 not being installed, go to the visual studio installer and add .NET Framework 3.5 Developer Tools from the Individual Components tab and install [Microsoft .NET Framework 3.5 Service Pack 1](https://www.microsoft.com/en-us/download/details.aspx?id=22\&desc=dotnet35) then restart your VM
{% endhint %}

If the build is successful, you should see the Seatbelt executable in your artifacts tab, if you cannot find it here then add the `C:\BuildAgent` directory to your Defender exclusions (if you've installed an agent post server setup)

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FzD0BoM45kPhdJ3WQ5qNG%2Fimage.png?alt=media&#x26;token=57f5483a-476b-45c8-8a3e-7e471c76c755" alt=""><figcaption><p>Successful Build</p></figcaption></figure>

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FW6lE3Y8wxjUhbr5ZtJFG%2Fimage.png?alt=media&#x26;token=bee0c713-f3a6-4afd-9b38-6fc40fc1919d" alt=""><figcaption><p>Seatbelt Executing Successfully</p></figcaption></figure>

You can download the artifact by clicking on its name. You might need to add another exclusion at `C:\ProgramData\JetBrains\TeamCity`. We will take a look at how to make the binary less detectable in the next chapter.

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FQdJesNIzBluHrlTHBVZD%2Fimage.png?alt=media&#x26;token=0c1ff251-8a86-4504-9ca5-aaf0786e7e57" alt=""><figcaption><p>Defender nuking our artifact</p></figcaption></figure>

### Private Repositories

Pulling from private repositories is just as easy as from public ones, the only difference is that private repositories must be accessible and you must have the necessary credentials to access them.

If you recall from the [previous module](https://blog.securescape.cc/offensive-security/red-team/offensive-development/offensive-devops/teamcity-setup#ssh-key-s),  we added our SSH key and created an access token. We will use these to pull the repository - the same can be done for GitHub using Personal Access Tokens or SSH keys.

Let's try pulling our calculator project, then testing and building it using TeamCity

<pre class="language-powershell"><code class="lang-powershell"><strong># Double check your connection to your GitLab server from TeamCity's server
</strong><strong>PS> ping 192.168.8.142
</strong>
Pinging 192.168.8.142 with 32 bytes of data:
Reply from 192.168.8.142: bytes=32 time&#x3C;1ms TTL=64
Reply from 192.168.8.142: bytes=32 time&#x3C;1ms TTL=64
</code></pre>

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FQJKFBRUPJTZr8jDptVgF%2Fimage.png?alt=media&#x26;token=7bda4e06-ebdb-4b33-b65a-d17d2c04fcf5" alt=""><figcaption><p>Add your credentials and the repo</p></figcaption></figure>

If successful, you should see this screen:

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FSIs8QtLLbBFDNYu9b5V6%2Fimage.png?alt=media&#x26;token=4f998822-9b05-427f-9796-761362c9cf88" alt=""><figcaption><p>Successful authentication</p></figcaption></figure>

Go to the next section, then click on Build Features - we have to enable the Golang feature to be able to run Go commands

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FOoOFAQl1b5l6lm91ErJ4%2Fimage.png?alt=media&#x26;token=b8a1365a-9551-4e45-86cb-83e1be63451c" alt=""><figcaption><p>Golang build feature</p></figcaption></figure>

Go back to Build Steps, then in the Command Line option paste this in:&#x20;

```batch
go test -json ./...
exit 0
```

This will run a test on all the folders within the project.

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2FWnd52IXCHFX9gU5p9hzL%2Fimage.png?alt=media&#x26;token=ab7acbeb-e3a5-460e-9ea3-f79cd8eff601" alt=""><figcaption><p>Command Line options</p></figcaption></figure>

Save and run this step. If the build succeeds, you should see a tab called Tests and the two test cases that we have set in [simple-calculator-project](https://blog.securescape.cc/offensive-security/red-team/offensive-development/offensive-devops/gitlab/simple-calculator-project "mention")

<figure><img src="https://1797977785-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjrIJ5xrJuOVgeeYdKNB5%2Fuploads%2Fkdml62q61XGIk6LsofS3%2Fimage.png?alt=media&#x26;token=f5ab58b7-fad8-4d8c-b3ac-1f72e2dbe5f6" alt=""><figcaption><p>Tests succeeded</p></figcaption></figure>

You can add a second build step after the test with `go build ./... -o calculator` to get your executable
