Published writing

Blog

Browse recent posts, filter by category, and move through the archive five posts at a time.

18 posts
Clear filter

Creating a SystemD service to run a self hosted devops agent.

I have the need to run an Azure Devops Agent as a systemD. Typcially I would just run it inside a container. But due to requirements on this system and pipeline I am unable to simply run inside a container. The belows assumes you have an agent already setup. Lets get started.

Creating the service file

First, lets go over the structure of a systemd service file.

There are three important sections. They are [Unit], [Service], and [Install]. The extension is .service and we can make comments with the hash symbol(#).

Lets create a file

[Unit]
Description=Devops Service
After=multi-user.target

[Service]
ExecStart=/home/[username]/myagent/run.sh
WorkingDirectory=/home/[username]/myagent/
User=opc
Group=opc
Restart=always
Type=simple

[Install]
WantedBy=default.target

What does each section do?

The [Unit] section helps describe the service and when to start it. In this case we want to ensure the network is up before starting the service. You can include an

Read full post

Reinitialize cache for Offline Files - Windows

Reinitialize cache for Offline Files - Windows

There will be times that Windows Offline files will give you problems. Such as not showing the correct files. You can cause Windows to reinitialize the cache by changing the following registry options.

  • Locate the registry subkey using regedit.exe at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CSC

  • setting Start to 4

Read full post

MongoDB + Docker

Running MongoDB on Docker

MongoDB is not your typical database. It is a NoSQL variant that stores data in an document based format. There are several advantages and disadvantages that I will not go into details in this post. In this document we will go over how to quickly setup a MongoDB instance inside an docker container along with adding data and running a query against it.

Downloading the Pre-existing Mongo container.

sudo docker pull mongo

Create Your Mount Partition

Docker containers are volatile. This means that when you shutdown the container any changes to any of the files inside a container are lost. The default Mongo container mounts the databases under the /data/db path. We can map that path with a path on the physicals host with the below command.

Create a directory to store your data with the following command.

sudo mkdir -p /data/mongo

When you run the container you will want to map the /data/mongo directory path with /data/db using the following command.

Read full post

Learning RUST by creating a basic C2!

Learning RUST by creating a basic C2!

The first that that I programmed in Rust was before version 1 was released. Rust is currently sitting at version 1.46. I wanted a quick project to review the language in the current form. The project I decided on was to write a very basic C2.

The code below launches a TCP stream that connects to a netcat session and starts a command session that redirects the STDIO and STDERR streams.

This project allowed great insight into how threading worked in Rust. Below is the code that I ended up with. Again, this is very basic and the structure could be cleaned up.

#![allow(unused)]

#[macro_use]
extern crate lazy_static;

use std::process::ChildStdin;
use std::process::Command;

use std::io::Write;
use std::process::Stdio;
use std::str;
use std::io::{BufRead, BufReader, BufWriter};
use std::thread;
use std::time;
use std::io::Read;
use std::sync::{Arc, Mutex};
use std::io::{stdin,stdout};

use std::net::TcpStream;
use std::io::prelude::*;
use tokio::io::split;

struct tcpStructure {
 
Read full post

Printing PDF to Multiple Printers

Printing PDF to Multiple Printers

There was a request to be able to print a PDF document to several printers with minimal work. I have worked on projects that utilized c# that received input from other systems to work behind the scenes with no user intervention. This task was slightly different as the PDF was manually being created. After some research in the Acrobat Reader documentation, it appears that the AcroRd32.exe executable accepts parameters to specify that you would like a document to be printed.

It was decided that utilizing a batch script would be the easiest route. The batch script accepts the location of a PDF file and passes the file into a command that specifies the filename and printer. Below code is an example of the batch file.

SET file=[Path To PDF File]

"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /t %file% "[PrinterName]1"

"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /t %file% "[PrinterName]2"
Read full post