A Writ of Habeas Corpus is a civil proceeding that is available in both State and Federal Court to challenge the legality of imprisonment. To get a writ of habeas corpus, you must file a petition for a civil (not criminal) proceeding in either state or federal court.A writ of habeas corpus is used to bring a prisoner or other detainee (e.g. The "Great Writ" of habeas corpus is a fundamental right in the Constitution that protects against unlawful and indefinite imprisonment. Under New York State law, a writ of habeas corpus serves a different purpose. It is not used to contest the validity of a criminal conviction. When properly used, a writ of habeas corpus can compel the release of an inmate. The writ of habeas corpus is used to attack an unlawful detention or illegal imprisonment. This petition, called a writ of Habeas Corpus, is filed in Federal Court (US District Court ) whether you are serving time in a federal or state prison. A petition for a writ of habeas corpus is a legal challenge to the lawfulness of a person's imprisonment.